Minor. fixes after review
This commit is contained in:
+2
@@ -92,6 +92,8 @@ public class JvmSerializerExtension extends SerializerExtension {
|
||||
|
||||
if (flexibleType instanceof RawTypeImpl) {
|
||||
lowerProto.setExtension(JvmProtoBuf.isRaw, true);
|
||||
|
||||
// we write this Extension for compatibility with old compiler
|
||||
upperProto.setExtension(JvmProtoBuf.isRaw, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,15 +92,7 @@ public class PossiblyBareType {
|
||||
return isBareTypeNullable() ? this : bare(getBareTypeConstructor(), true);
|
||||
}
|
||||
|
||||
KotlinType nullableActualType = TypeUtils.makeNullable(getActualType());
|
||||
|
||||
AbbreviatedType abbreviatedType = SpecialTypesKt.getAbbreviatedType(getActualType());
|
||||
if (abbreviatedType == null) {
|
||||
return type(nullableActualType);
|
||||
}
|
||||
else {
|
||||
return type(abbreviatedType.makeNullableAsSpecified(true));
|
||||
}
|
||||
return type(TypeUtils.makeNullable(getActualType()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// FILE: B.java
|
||||
import java.util.List
|
||||
|
||||
public class B implements X {
|
||||
@Override
|
||||
List foo(List l) {
|
||||
return super.foo(l);
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
interface X {
|
||||
fun foo(l: MutableList<Int>): List<String>?
|
||||
}
|
||||
|
||||
internal class C : B()
|
||||
@@ -0,0 +1,24 @@
|
||||
package
|
||||
|
||||
public open class B : X {
|
||||
public constructor B()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@java.lang.Override() public/*package*/ open override /*1*/ fun foo(/*0*/ l: kotlin.collections.MutableList<(raw) kotlin.Any?>): kotlin.collections.List<(raw) kotlin.Any?>?
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
internal final class C : B {
|
||||
public constructor C()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
@java.lang.Override() public/*package*/ open override /*1*/ /*fake_override*/ fun foo(/*0*/ l: kotlin.collections.MutableList<(raw) kotlin.Any?>): kotlin.collections.List<(raw) kotlin.Any?>?
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface X {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(/*0*/ l: kotlin.collections.MutableList<kotlin.Int>): kotlin.collections.List<kotlin.String>?
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,6 @@ public class A<T> {
|
||||
|
||||
// FILE: B.java
|
||||
|
||||
// TODO: E shoult has supertype A<*> which is raw type
|
||||
public class B<E extends A> {
|
||||
public E foo() { return null;}
|
||||
E field;
|
||||
@@ -27,6 +26,7 @@ public class Test {
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo(x: B<*>) {
|
||||
// TODO: x.foo() now is flexible type instead of raw, because of captured type approximation
|
||||
val q: MutableList<String> = x.foo().getChildrenStubs()
|
||||
|
||||
// Raw(B).field erased to A<Any!>..A<out Any!>?
|
||||
|
||||
@@ -13475,6 +13475,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rawEnhancment.kt")
|
||||
public void testRawEnhancment() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawEnhancment.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rawSupertype.kt")
|
||||
public void testRawSupertype() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawSupertype.kt");
|
||||
|
||||
+4
-2
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType(lowerBound, upperBound), RawType {
|
||||
init {
|
||||
@@ -66,7 +67,7 @@ class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType
|
||||
if (options.debugMode) {
|
||||
return "raw ($lowerRendered..$upperRendered)"
|
||||
}
|
||||
if (upperBound.arguments.isEmpty()) return renderer.renderFlexibleType(lowerRendered, upperRendered)
|
||||
if (upperBound.arguments.isEmpty()) return renderer.renderFlexibleType(lowerRendered, upperRendered, builtIns)
|
||||
|
||||
val lowerArgs = renderArguments(lowerBound)
|
||||
val upperArgs = renderArguments(upperBound)
|
||||
@@ -77,7 +78,7 @@ class RawTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : FlexibleType
|
||||
else upperRendered
|
||||
val newLower = lowerRendered.replaceArgs(newArgs)
|
||||
if (newLower == newUpper) return newLower
|
||||
return renderer.renderFlexibleType(newLower, newUpper)
|
||||
return renderer.renderFlexibleType(newLower, newUpper, builtIns)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +107,7 @@ internal object RawSubstitution : TypeSubstitution() {
|
||||
}
|
||||
}
|
||||
|
||||
// false means that type cannot be raw
|
||||
private fun eraseInflexibleBasedOnClassDescriptor(
|
||||
type: SimpleType, declaration: ClassDescriptor, attr: JavaTypeAttributes
|
||||
): Pair<SimpleType, Boolean> {
|
||||
|
||||
+9
-3
@@ -58,7 +58,7 @@ private open class Result(open val type: KotlinType, val subtreeSize: Int, val w
|
||||
private class SimpleResult(override val type: SimpleType, subtreeSize: Int, wereChanges: Boolean): Result(type, subtreeSize, wereChanges)
|
||||
|
||||
private fun UnwrappedType.enhancePossiblyFlexible(qualifiers: (Int) -> JavaTypeQualifiers, index: Int): Result {
|
||||
if (isError || this is RawTypeImpl) return Result(this, 1, false) // todo: Raw
|
||||
if (isError) return Result(this, 1, false)
|
||||
return when(this) {
|
||||
is FlexibleType -> {
|
||||
val lowerResult = lowerBound.enhanceInflexible(qualifiers, index, TypeComponentPosition.FLEXIBLE_LOWER)
|
||||
@@ -71,8 +71,14 @@ private fun UnwrappedType.enhancePossiblyFlexible(qualifiers: (Int) -> JavaTypeQ
|
||||
|
||||
val wereChanges = lowerResult.wereChanges || upperResult.wereChanges
|
||||
Result(
|
||||
if (wereChanges)
|
||||
KotlinTypeFactory.flexibleType(lowerResult.type, upperResult.type)
|
||||
if (wereChanges) {
|
||||
if (this is RawTypeImpl) {
|
||||
RawTypeImpl(lowerResult.type, upperResult.type)
|
||||
}
|
||||
else {
|
||||
KotlinTypeFactory.flexibleType(lowerResult.type, upperResult.type)
|
||||
}
|
||||
}
|
||||
else
|
||||
this@enhancePossiblyFlexible,
|
||||
lowerResult.subtreeSize,
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class KotlinBuiltIns {
|
||||
private final Set<PackageFragmentDescriptor> builtInsPackageFragments;
|
||||
|
||||
private final Map<PrimitiveType, SimpleType> primitiveTypeToArrayKotlinType;
|
||||
private final Map<SimpleType, SimpleType> primitiveKotlinTypeToKotlinArrayType;
|
||||
private final Map<KotlinType, SimpleType> primitiveKotlinTypeToKotlinArrayType;
|
||||
private final Map<SimpleType, SimpleType> kotlinArrayTypeToPrimitiveKotlinType;
|
||||
private final StorageManager storageManager;
|
||||
|
||||
@@ -109,7 +109,7 @@ public abstract class KotlinBuiltIns {
|
||||
builtInsPackageFragments = new LinkedHashSet<PackageFragmentDescriptor>(packageNameToPackageFragment.values());
|
||||
|
||||
primitiveTypeToArrayKotlinType = new EnumMap<PrimitiveType, SimpleType>(PrimitiveType.class);
|
||||
primitiveKotlinTypeToKotlinArrayType = new HashMap<SimpleType, SimpleType>();
|
||||
primitiveKotlinTypeToKotlinArrayType = new HashMap<KotlinType, SimpleType>();
|
||||
kotlinArrayTypeToPrimitiveKotlinType = new HashMap<SimpleType, SimpleType>();
|
||||
for (PrimitiveType primitive : PrimitiveType.values()) {
|
||||
makePrimitive(primitive);
|
||||
@@ -710,7 +710,7 @@ public abstract class KotlinBuiltIns {
|
||||
*/
|
||||
@Nullable
|
||||
public SimpleType getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(@NotNull KotlinType kotlinType) {
|
||||
return primitiveKotlinTypeToKotlinArrayType.get(kotlinType); // todo unwrap
|
||||
return primitiveKotlinTypeToKotlinArrayType.get(kotlinType);
|
||||
}
|
||||
|
||||
public static boolean isPrimitiveArray(@NotNull FqNameUnsafe arrayFqName) {
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
public SimpleType invoke() {
|
||||
return KotlinTypeFactory.simpleType(
|
||||
Annotations.Companion.getEMPTY(),
|
||||
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
|
||||
getTypeConstructor(), Collections.<TypeProjection>emptyList(), false,
|
||||
new LazyScopeAdapter(storageManager.createLazyValue(
|
||||
new Function0<MemberScope>() {
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.renderer
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
@@ -38,7 +39,7 @@ abstract class DescriptorRenderer {
|
||||
|
||||
abstract fun renderType(type: KotlinType): String
|
||||
|
||||
abstract fun renderFlexibleType(lowerRendered: String, upperRendered: String): String
|
||||
abstract fun renderFlexibleType(lowerRendered: String, upperRendered: String, builtIns: KotlinBuiltIns): String
|
||||
|
||||
abstract fun renderTypeArguments(typeArguments: List<TypeProjection>): String
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ internal class DescriptorRendererImpl(
|
||||
return type.isFunctionType && type.arguments.none { it.isStarProjection }
|
||||
}
|
||||
|
||||
override fun renderFlexibleType(lowerRendered: String, upperRendered: String): String {
|
||||
override fun renderFlexibleType(lowerRendered: String, upperRendered: String, builtIns: KotlinBuiltIns): String {
|
||||
if (differsOnlyInNullability(lowerRendered, upperRendered)) {
|
||||
if (upperRendered.startsWith("(")) {
|
||||
// the case of complex type, e.g. (() -> Unit)?
|
||||
@@ -178,7 +178,7 @@ internal class DescriptorRendererImpl(
|
||||
return lowerRendered + "!"
|
||||
}
|
||||
|
||||
val kotlinCollectionsPrefix = classifierNamePolicy.renderClassifier(DefaultBuiltIns.Instance.collection, this).substringBefore("Collection")
|
||||
val kotlinCollectionsPrefix = classifierNamePolicy.renderClassifier(builtIns.collection, this).substringBefore("Collection")
|
||||
val mutablePrefix = "Mutable"
|
||||
// java.util.List<Foo> -> (Mutable)List<Foo!>!
|
||||
val simpleCollection = replacePrefixes(lowerRendered, kotlinCollectionsPrefix + mutablePrefix, upperRendered, kotlinCollectionsPrefix, kotlinCollectionsPrefix + "(" + mutablePrefix + ")")
|
||||
@@ -187,7 +187,7 @@ internal class DescriptorRendererImpl(
|
||||
val mutableEntry = replacePrefixes(lowerRendered, kotlinCollectionsPrefix + "MutableMap.MutableEntry", upperRendered, kotlinCollectionsPrefix + "Map.Entry", kotlinCollectionsPrefix + "(Mutable)Map.(Mutable)Entry")
|
||||
if (mutableEntry != null) return mutableEntry
|
||||
|
||||
val kotlinPrefix = classifierNamePolicy.renderClassifier(DefaultBuiltIns.Instance.array, this).substringBefore("Array")
|
||||
val kotlinPrefix = classifierNamePolicy.renderClassifier(builtIns.array, this).substringBefore("Array")
|
||||
// Foo[] -> Array<(out) Foo!>!
|
||||
val array = replacePrefixes(lowerRendered, kotlinPrefix + escape("Array<"), upperRendered, kotlinPrefix + escape("Array<out "), kotlinPrefix + escape("Array<(out) "))
|
||||
if (array != null) return array
|
||||
|
||||
@@ -92,6 +92,7 @@ private fun substituteCapturedTypesWithProjections(typeProjection: TypeProjectio
|
||||
return typeSubstitutor.substituteWithoutApproximation(typeProjection)
|
||||
}
|
||||
|
||||
// todo: dynamic & raw type?
|
||||
fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType> {
|
||||
if (type.isFlexible()) {
|
||||
val boundsForFlexibleLower = approximateCapturedTypes(type.lowerIfFlexible())
|
||||
|
||||
@@ -96,9 +96,6 @@ abstract class SimpleType : UnwrappedType() {
|
||||
abstract override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType
|
||||
|
||||
override fun toString(): String {
|
||||
// for error types this method should be overridden
|
||||
if (isError) return "ErrorType"
|
||||
|
||||
return buildString {
|
||||
for ((annotation, target) in annotations.getAllAnnotations()) {
|
||||
append("[", DescriptorRenderer.DEBUG_TEXT.renderAnnotation(annotation, target), "] ")
|
||||
|
||||
@@ -154,14 +154,12 @@ fun KotlinType.contains(predicate: (KotlinType) -> Boolean) = TypeUtils.contains
|
||||
|
||||
fun KotlinType.replaceArgumentsWithStarProjections(): KotlinType {
|
||||
val unwrapped = unwrap()
|
||||
if (unwrapped is FlexibleType) {
|
||||
return KotlinTypeFactory.flexibleType(
|
||||
return when (unwrapped) {
|
||||
is FlexibleType -> KotlinTypeFactory.flexibleType(
|
||||
unwrapped.lowerBound.replaceArgumentsWithStarProjections(),
|
||||
unwrapped.upperBound.replaceArgumentsWithStarProjections()
|
||||
)
|
||||
}
|
||||
else {
|
||||
return (unwrapped as SimpleType).replaceArgumentsWithStarProjections()
|
||||
is SimpleType -> unwrapped.replaceArgumentsWithStarProjections()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
|
||||
|
||||
fun KotlinType.isFlexible(): Boolean = unwrap() is FlexibleType
|
||||
@@ -127,7 +128,7 @@ class FlexibleTypeImpl(lowerBound: SimpleType, upperBound: SimpleType) : Flexibl
|
||||
if (options.debugMode) {
|
||||
return "(${renderer.renderType(lowerBound)}..${renderer.renderType(upperBound)})"
|
||||
}
|
||||
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound))
|
||||
return renderer.renderFlexibleType(renderer.renderType(lowerBound), renderer.renderType(upperBound), builtIns)
|
||||
}
|
||||
|
||||
override fun makeNullableAsSpecified(newNullability: Boolean): UnwrappedType
|
||||
|
||||
+2
-3
@@ -24,8 +24,7 @@ interface FlexibleTypeDeserializer {
|
||||
fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
|
||||
object ThrowException : FlexibleTypeDeserializer {
|
||||
private fun error(): Nothing = throw IllegalArgumentException("This factory should not be used.")
|
||||
|
||||
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType = error()
|
||||
override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType
|
||||
= throw IllegalArgumentException("This method should not be used.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user