Allow top-level type aliases in scripts
This commit is contained in:
@@ -698,7 +698,8 @@ public class DescriptorResolver {
|
||||
@NotNull KtTypeAlias typeAlias,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
if (!(containingDeclaration instanceof PackageFragmentDescriptor)) {
|
||||
if (!(containingDeclaration instanceof PackageFragmentDescriptor) &&
|
||||
!(containingDeclaration instanceof ScriptDescriptor)) {
|
||||
trace.report(TOPLEVEL_TYPEALIASES_ONLY.on(typeAlias));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class SimpleClass(val s: String) {
|
||||
fun foo() = s
|
||||
}
|
||||
|
||||
typealias Test = SimpleClass
|
||||
|
||||
val rv = Test("OK").foo()
|
||||
|
||||
// expected: rv: OK
|
||||
@@ -0,0 +1,9 @@
|
||||
typealias TopLevelInScript = String
|
||||
|
||||
class C {
|
||||
<!TOPLEVEL_TYPEALIASES_ONLY!>typealias NestedInClass = String<!>
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
<!TOPLEVEL_TYPEALIASES_ONLY!>typealias Local = String<!>
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package
|
||||
|
||||
public final class TypealiasInScript : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor TypealiasInScript(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public final class C {
|
||||
public constructor C()
|
||||
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
|
||||
public typealias NestedInClass = kotlin.String
|
||||
}
|
||||
public typealias TopLevelInScript = kotlin.String
|
||||
}
|
||||
@@ -23605,6 +23605,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/topLevelVariable.kts");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typealiasInScript.kts")
|
||||
public void testTypealiasInScript() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/script/typealiasInScript.kts");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/diagnostics")
|
||||
|
||||
@@ -173,4 +173,10 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/topLevelProperty.kts");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelTypealias.kts")
|
||||
public void testTopLevelTypealias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/topLevelTypealias.kts");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user