KT-6698 Bad class file when using a star-projection on a Java's recursive generic parameter

#KT-6698 Fixed
This commit is contained in:
Andrey Breslav
2015-01-30 18:49:30 +03:00
parent 8d5a6d729e
commit da639039bd
61 changed files with 996 additions and 847 deletions
@@ -91,9 +91,12 @@ class LazyJavaTypeResolver(
val typeParameter: TypeParameterDescriptor,
val attr: JavaTypeAttributes
) : TypeProjectionBase() {
override fun isStarProjection() = true
override fun getProjectionKind() =
// projections are not allowed in immediate arguments of supertypes
if (typeParameter.getVariance() == OUT_VARIANCE || attr.howThisTypeIsUsed == SUPERTYPE) INVARIANT else OUT_VARIANCE
override fun getType() = typeParameter.getUpperBoundsAsType()
}
@@ -480,10 +480,15 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private void appendTypeProjections(@NotNull List<TypeProjection> typeProjections, @NotNull StringBuilder builder) {
for (Iterator<TypeProjection> iterator = typeProjections.iterator(); iterator.hasNext(); ) {
TypeProjection typeProjection = iterator.next();
if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
builder.append(typeProjection.getProjectionKind()).append(" ");
if (typeProjection.isStarProjection()) {
builder.append("*");
}
else {
if (typeProjection.getProjectionKind() != Variance.INVARIANT) {
builder.append(typeProjection.getProjectionKind()).append(" ");
}
builder.append(renderNormalizedType(typeProjection.getType()));
}
builder.append(renderNormalizedType(typeProjection.getType()));
if (iterator.hasNext()) {
builder.append(", ");
}
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
class StarProjectionImpl(
private val _type: JetType
) : TypeProjectionBase() {
override fun isStarProjection() = true
override fun getProjectionKind() = Variance.OUT_VARIANCE
override fun getType() = _type
}
@@ -24,4 +24,6 @@ public interface TypeProjection {
@NotNull
JetType getType();
boolean isStarProjection();
}
@@ -20,6 +20,9 @@ public abstract class TypeProjectionBase implements TypeProjection {
@Override
public String toString() {
if (isStarProjection()) {
return "*";
}
if (getProjectionKind() == Variance.INVARIANT) {
return getType().toString();
}
@@ -42,4 +42,9 @@ public class TypeProjectionImpl extends TypeProjectionBase {
public JetType getType() {
return type;
}
@Override
public boolean isStarProjection() {
return false;
}
}
@@ -584,9 +584,7 @@ public class TypeUtils {
@NotNull
public static TypeProjection makeStarProjection(@NotNull TypeParameterDescriptor parameterDescriptor) {
return new TypeProjectionImpl(parameterDescriptor.getVariance() == Variance.OUT_VARIANCE
? Variance.INVARIANT
: Variance.OUT_VARIANCE, parameterDescriptor.getUpperBoundsAsType());
return new StarProjectionImpl(parameterDescriptor.getUpperBoundsAsType());
}
@Nullable