DeclarationsChecker runs checks on type alias declarations.
TYPEALIAS_SHOULD_EXPAND_TO_CLASS diagnostics (implemented for type aliases expanded to type parameters).
This commit is contained in:
@@ -120,6 +120,7 @@ public interface Errors {
|
||||
DiagnosticFactory3<KtElement, KotlinType, KotlinType, ClassifierDescriptor> UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION =
|
||||
DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory1<KtElement, KotlinType> CONFLICTING_PROJECTION_IN_TYPEALIAS_EXPANSION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtTypeReference, KotlinType> TYPEALIAS_SHOULD_EXPAND_TO_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
+1
@@ -424,6 +424,7 @@ public class DefaultErrorMessages {
|
||||
"should be subtype of ''{0}'', substituted type is ''{1}''",
|
||||
RENDER_TYPE, RENDER_TYPE, NAME);
|
||||
MAP.put(CONFLICTING_PROJECTION_IN_TYPEALIAS_EXPANSION, "Conflicting projection in type alias expansion in intermediate type ''{0}''", RENDER_TYPE);
|
||||
MAP.put(TYPEALIAS_SHOULD_EXPAND_TO_CLASS, "Type alias expands to {0}, which is not a class, an interface, or an object", RENDER_TYPE);
|
||||
|
||||
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
|
||||
|
||||
@@ -140,6 +140,25 @@ class DeclarationsChecker(
|
||||
checkConstructorDeclaration(constructorDescriptor, declaration)
|
||||
exposedChecker.checkFunction(declaration, constructorDescriptor)
|
||||
}
|
||||
|
||||
for ((declaration, typeAliasDescriptor) in bodiesResolveContext.typeAliases.entries) {
|
||||
checkTypeAliasDeclaration(typeAliasDescriptor, declaration)
|
||||
modifiersChecker.checkModifiersForDeclaration(declaration, typeAliasDescriptor)
|
||||
// TODO exposedChecker.checkTypeAlias(declaration, typeAliasDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkTypeAliasDeclaration(typeAliasDescriptor: TypeAliasDescriptor, declaration: KtTypeAlias) {
|
||||
val typeReference = declaration.getTypeReference()
|
||||
if (typeReference == null) return
|
||||
|
||||
val expandedType = typeAliasDescriptor.expandedType // TODO refactor type alias expansion
|
||||
if (expandedType.isError) return
|
||||
|
||||
val expandedClassifier = expandedType.constructor.declarationDescriptor
|
||||
if (expandedClassifier is TypeParameterDescriptor) {
|
||||
trace.report(TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, expandedType))
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkConstructorDeclaration(constructorDescriptor: ConstructorDescriptor, declaration: KtDeclaration) {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
typealias ToTypeParam1<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>T<!>
|
||||
typealias ToTypeParam2<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>ToTypeParam1<T><!>
|
||||
typealias ToTypeParam3<T1, T2> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>ToTypeParam2<T1><!>
|
||||
typealias ToTypeParam4 = ToTypeParam1<Any>
|
||||
|
||||
typealias ToFun1 = () -> Unit
|
||||
typealias ToFun2<T> = (T) -> Unit
|
||||
|
||||
class Outer {
|
||||
typealias ToTypeParam1<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>T<!>
|
||||
typealias ToTypeParam2<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>ToTypeParam1<T><!>
|
||||
typealias ToTypeParam3<T1, T2> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>ToTypeParam2<T1><!>
|
||||
typealias ToTypeParam4 = ToTypeParam1<Any>
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
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>
|
||||
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>
|
||||
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
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -19410,6 +19410,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasShouldExpandToClass.kt")
|
||||
public void testTypeAliasShouldExpandToClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasShouldExpandToClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unsupportedTypeAlias.kt")
|
||||
public void testUnsupportedTypeAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/unsupportedTypeAlias.kt");
|
||||
|
||||
Reference in New Issue
Block a user