Fix type alias problems after rebase.

This commit is contained in:
Stanislav Erokhin
2016-06-09 15:51:34 +03:00
parent db3e0798c8
commit 53bf720503
6 changed files with 32 additions and 35 deletions
@@ -725,7 +725,7 @@ public class DescriptorResolver {
ErrorUtils.createErrorType(name.asString()));
}
else if (!languageFeatureSettings.supportsFeature(LanguageFeature.TypeAliases)) {
typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace, true);
typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
PsiElement typeAliasKeyword = typeAlias.getTypeAliasKeyword();
trace.report(UNSUPPORTED_TYPEALIAS.on(typeAliasKeyword != null ? typeAliasKeyword : typeAlias));
typeAliasDescriptor.initialize(
@@ -739,14 +739,13 @@ public class DescriptorResolver {
storageManager.createLazyValue(new Function0<SimpleType>() {
@Override
public SimpleType invoke() {
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace, true);
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
}
}),
storageManager.createLazyValue(new Function0<SimpleType>() {
@Override
public SimpleType invoke() {
// TODO do not reparse
return typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace, false);
return typeResolver.resolveExpandedTypeForTypeAlias(typeAliasDescriptor);
}
}));
}
@@ -71,23 +71,20 @@ class TypeResolver(
return resolveType(TypeResolutionContext(scope, trace, checkBounds, false, typeReference.suppressDiagnosticsInDebugMode(), false), typeReference)
}
fun resolveAbbreviatedType(scope: LexicalScope, typeReference: KtTypeReference, trace: BindingTrace, abbreviated: Boolean): SimpleType {
return resolveSimpleType(
TypeResolutionContext(scope, trace, true, false, typeReference.suppressDiagnosticsInDebugMode(), abbreviated),
typeReference
)
}
private fun resolveSimpleType(c: TypeResolutionContext, typeReference: KtTypeReference): SimpleType {
val unwrappedType = resolveType(c, typeReference).unwrap()
return when (unwrappedType) {
is DynamicType -> ErrorUtils.createErrorType("dynamic type in wrong context")
is SimpleType -> unwrappedType
else -> error("Unexpected type: $unwrappedType")
fun resolveAbbreviatedType(scope: LexicalScope, typeReference: KtTypeReference, trace: BindingTrace): SimpleType {
val resolvedType = resolveType(TypeResolutionContext(scope, trace, true, false, typeReference.suppressDiagnosticsInDebugMode(), true),
typeReference).unwrap()
return when (resolvedType) {
is DynamicType -> {
trace.report(Errors.TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, resolvedType))
ErrorUtils.createErrorType("dynamic type in wrong context")
}
is SimpleType -> resolvedType
else -> error("Unexpected type: $resolvedType")
}
}
fun resolveExpandedTypeForTypeAlias(typeAliasDescriptor: TypeAliasDescriptor): KotlinType {
fun resolveExpandedTypeForTypeAlias(typeAliasDescriptor: TypeAliasDescriptor): SimpleType {
val typeAliasExpansion = TypeAliasExpansion.createWithFormalArguments(typeAliasDescriptor)
val expandedType = TypeAliasExpander.NON_REPORTING.expandWithoutAbbreviation(typeAliasExpansion, Annotations.EMPTY)
return expandedType
@@ -44,8 +44,8 @@ class DescriptorSerializer private constructor(
}.toByteArray()
}
private fun createChildSerializer(callable: CallableDescriptor): DescriptorSerializer =
DescriptorSerializer(callable, Interner(typeParameters), extension, typeTable, serializeTypeTableToFunction = false)
private fun createChildSerializer(descriptor: DeclarationDescriptor): DescriptorSerializer =
DescriptorSerializer(descriptor, Interner(typeParameters), extension, typeTable, serializeTypeTableToFunction = false)
val stringTable: StringTable
get() = extension.stringTable
@@ -277,6 +277,7 @@ class DescriptorSerializer private constructor(
fun typeAliasProto(descriptor: TypeAliasDescriptor): ProtoBuf.TypeAlias.Builder {
val builder = ProtoBuf.TypeAlias.newBuilder()
val local = createChildSerializer(descriptor)
val flags = Flags.getTypeAliasFlags(hasAnnotations(descriptor), descriptor.visibility)
if (flags != builder.flags) {
@@ -286,23 +287,23 @@ class DescriptorSerializer private constructor(
builder.name = getSimpleNameIndex(descriptor.name)
for (typeParameterDescriptor in descriptor.declaredTypeParameters) {
builder.addTypeParameter(typeParameter(typeParameterDescriptor))
builder.addTypeParameter(local.typeParameter(typeParameterDescriptor))
}
val underlyingType = descriptor.underlyingType
if (useTypeTable()) {
builder.underlyingTypeId = typeId(underlyingType)
builder.underlyingTypeId = local.typeId(underlyingType)
}
else {
builder.setUnderlyingType(type(underlyingType))
builder.setUnderlyingType(local.type(underlyingType))
}
val expandedType = descriptor.expandedType
if (useTypeTable()) {
builder.expandedTypeId = typeId(expandedType)
builder.expandedTypeId = local.typeId(expandedType)
}
else {
builder.setExpandedType(type(expandedType))
builder.setExpandedType(local.type(expandedType))
}
return builder
@@ -3,15 +3,15 @@ package
public typealias ToFun1 = () -> kotlin.Unit
public typealias ToFun2</*0*/ T> = (T) -> kotlin.Unit
public typealias ToTypeParam1</*0*/ T> = T
public typealias ToTypeParam2</*0*/ T> = ToTypeParam1<T> [= T]
public typealias ToTypeParam3</*0*/ T1, /*1*/ T2> = ToTypeParam2<T1> [= T1]
public typealias ToTypeParam4 = ToTypeParam1<kotlin.Any> [= kotlin.Any]
public typealias ToTypeParam2</*0*/ T> = ToTypeParam1<T>
public typealias ToTypeParam3</*0*/ T1, /*1*/ T2> = ToTypeParam2<T1>
public typealias ToTypeParam4 = ToTypeParam1<kotlin.Any>
public final class Outer {
public typealias ToTypeParam1</*0*/ T> = T
public typealias ToTypeParam2</*0*/ T> = Outer.ToTypeParam1<T> [= T]
public typealias ToTypeParam3</*0*/ T1, /*1*/ T2> = Outer.ToTypeParam2<T1> [= T1]
public typealias ToTypeParam4 = Outer.ToTypeParam1<kotlin.Any> [= kotlin.Any]
public typealias ToTypeParam2</*0*/ T> = Outer.ToTypeParam1<T>
public typealias ToTypeParam3</*0*/ T1, /*1*/ T2> = Outer.ToTypeParam2<T1>
public typealias ToTypeParam4 = Outer.ToTypeParam1<kotlin.Any>
public constructor Outer()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@@ -1,6 +1,6 @@
typealias Dyn = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>dynamic<!>
typealias Dyn2 = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>Dyn<!>
typealias Dyn3 = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>Dyn2<!>
typealias Dyn2 = Dyn
typealias Dyn3 = Dyn2
typealias Type<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>T<!>
typealias Dyn4 = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>Type<Dyn><!>
typealias Dyn4 = Type<Dyn>
@@ -1,6 +1,6 @@
package
public typealias Dyn = dynamic
public typealias Dyn = [ERROR : dynamic type in wrong context]
public typealias Dyn2 = Dyn
public typealias Dyn3 = Dyn2
public typealias Dyn4 = Type<Dyn>