Type alias can't expand to 'dynamic'
This commit is contained in:
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.resolve.BindingContext.TYPE
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.TYPE_PARAMETER
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.classCanHaveAbstractMembers
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.classCanHaveOpenMembers
|
||||
import org.jetbrains.kotlin.types.IntersectionTypeConstructor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SubstitutionUtils
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
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.isNothing
|
||||
@@ -149,14 +146,14 @@ class DeclarationsChecker(
|
||||
}
|
||||
|
||||
private fun checkTypeAliasDeclaration(typeAliasDescriptor: TypeAliasDescriptor, declaration: KtTypeAlias) {
|
||||
val typeReference = declaration.getTypeReference()
|
||||
if (typeReference == null) return
|
||||
val typeReference = declaration.getTypeReference() ?: return
|
||||
|
||||
val expandedType = typeAliasDescriptor.expandedType // TODO refactor type alias expansion
|
||||
if (expandedType.isError) return
|
||||
|
||||
val expandedClassifier = expandedType.constructor.declarationDescriptor
|
||||
if (expandedClassifier is TypeParameterDescriptor) {
|
||||
|
||||
if (expandedType.isDynamic() || expandedClassifier is TypeParameterDescriptor) {
|
||||
trace.report(TYPEALIAS_SHOULD_EXPAND_TO_CLASS.on(typeReference, expandedType))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,10 @@ class TypeAliasExpander(
|
||||
|
||||
val expandedType = expandRecursively(nestedExpansion, type.annotations, recursionDepth + 1, false)
|
||||
|
||||
return TypeProjectionImpl(originalProjection.projectionKind, expandedType.withAbbreviatedType(type))
|
||||
// 'dynamic' type can't be abbreviated - will be reported separately
|
||||
val typeWithAbbreviation = if (expandedType.isDynamic()) expandedType else expandedType.withAbbreviatedType(type)
|
||||
|
||||
return TypeProjectionImpl(originalProjection.projectionKind, typeWithAbbreviation)
|
||||
}
|
||||
else -> {
|
||||
val substitutedArguments = type.arguments.mapIndexed { i, originalArgument ->
|
||||
|
||||
Vendored
+6
@@ -0,0 +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 Type<T> = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>T<!>
|
||||
typealias Dyn4 = <!TYPEALIAS_SHOULD_EXPAND_TO_CLASS!>Type<Dyn><!>
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
package
|
||||
|
||||
public typealias Dyn = dynamic
|
||||
public typealias Dyn2 = Dyn
|
||||
public typealias Dyn3 = Dyn2
|
||||
public typealias Dyn4 = Type<Dyn>
|
||||
public typealias Type</*0*/ T> = T
|
||||
@@ -235,6 +235,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typealiasExpandingToDynamic.kt")
|
||||
public void testTypealiasExpandingToDynamic() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/typealiasExpandingToDynamic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("varargs.kt")
|
||||
public void testVarargs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/varargs.kt");
|
||||
|
||||
Reference in New Issue
Block a user