Type alias shouldn't expand to a malformed type (e.g., 'Array<Nothing>').
This commit is contained in:
@@ -123,6 +123,7 @@ public interface Errors {
|
||||
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);
|
||||
DiagnosticFactory2<KtTypeReference, KotlinType, String> TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
+1
@@ -427,6 +427,7 @@ public class DefaultErrorMessages {
|
||||
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(TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE, "Type alias expanded to malformed type {0}: {1}", RENDER_TYPE, STRING);
|
||||
|
||||
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils.classCanHaveOpenMembers
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import java.util.*
|
||||
|
||||
@@ -162,6 +163,10 @@ class DeclarationsChecker(
|
||||
if (expandedType.isDynamic() || expandedClassifier is TypeParameterDescriptor) {
|
||||
trace.report(TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, expandedType))
|
||||
}
|
||||
|
||||
if (TypeUtils.contains(expandedType) { it.isArrayOfNothing()} ) {
|
||||
trace.report(TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE.on(typeReference, expandedType, "Array<Nothing> is illegal"))
|
||||
}
|
||||
}
|
||||
|
||||
private class TypeAliasDeclarationCheckingReportStrategy(
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
typealias A<T> = Array<T>
|
||||
typealias AA<T> = A<A<T>>
|
||||
|
||||
typealias AN = <!TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE!>A<Nothing><!>
|
||||
|
||||
typealias AAN = <!TYPEALIAS_EXPANDED_TO_MALFORMED_TYPE!>AA<Nothing><!>
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
public typealias A</*0*/ T> = kotlin.Array<T>
|
||||
public typealias AA</*0*/ T> = A<A<T>>
|
||||
public typealias AAN = AA<kotlin.Nothing>
|
||||
public typealias AN = A<kotlin.Nothing>
|
||||
@@ -19509,6 +19509,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("illegalTypeInTypeAliasExpansion.kt")
|
||||
public void testIllegalTypeInTypeAliasExpansion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/illegalTypeInTypeAliasExpansion.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("import.kt")
|
||||
public void testImport() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/import.kt");
|
||||
|
||||
Reference in New Issue
Block a user