K2 scripting: support script-level typealiases
This commit is contained in:
committed by
Space Team
parent
70d2fcd9c4
commit
1a735b0842
@@ -741,7 +741,7 @@ val CheckerContext.closestNonLocal get() = containingDeclarations.takeWhile { it
|
||||
fun CheckerContext.closestNonLocalWith(declaration: FirDeclaration) =
|
||||
(containingDeclarations + declaration).takeWhile { it.isNonLocal }.lastOrNull()
|
||||
|
||||
val CheckerContext.isTopLevel get() = containingDeclarations.lastOrNull() is FirFile
|
||||
val CheckerContext.isTopLevel get() = containingDeclarations.lastOrNull().let { it is FirFile || it is FirScript }
|
||||
|
||||
fun FirBasedSymbol<*>.hasAnnotationOrInsideAnnotatedClass(classId: ClassId, session: FirSession): Boolean {
|
||||
if (hasAnnotation(classId, session)) return true
|
||||
|
||||
@@ -304,7 +304,7 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
fun registerTypeAlias(
|
||||
typeAlias: FirTypeAlias,
|
||||
parent: IrFile
|
||||
parent: IrDeclarationParent
|
||||
): IrTypeAlias {
|
||||
val signature = signatureComposer.composeSignature(typeAlias)
|
||||
return typeAlias.convertWithOffsets { startOffset, endOffset ->
|
||||
@@ -322,7 +322,9 @@ class Fir2IrClassifierStorage(
|
||||
).apply {
|
||||
this.parent = parent
|
||||
setTypeParameters(typeAlias)
|
||||
parent.declarations += this
|
||||
if (parent is IrFile) {
|
||||
parent.declarations += this
|
||||
}
|
||||
}
|
||||
typeAliasCache[typeAlias] = irTypeAlias
|
||||
irTypeAlias
|
||||
|
||||
@@ -359,15 +359,19 @@ class Fir2IrConverter(
|
||||
processRegularClassMembers(declaration)
|
||||
}
|
||||
is FirScript -> {
|
||||
assert(parent is IrFile)
|
||||
parent as IrFile
|
||||
declarationStorage.getOrCreateIrScript(declaration).also { irScript ->
|
||||
declarationStorage.enterScope(irScript)
|
||||
irScript.parent = parent
|
||||
for (scriptStatement in declaration.statements) {
|
||||
if (scriptStatement is FirDeclaration) {
|
||||
if (scriptStatement is FirRegularClass) {
|
||||
registerClassAndNestedClasses(scriptStatement, irScript)
|
||||
processClassAndNestedClassHeaders(scriptStatement)
|
||||
when (scriptStatement) {
|
||||
is FirRegularClass -> {
|
||||
registerClassAndNestedClasses(scriptStatement, irScript)
|
||||
processClassAndNestedClassHeaders(scriptStatement)
|
||||
}
|
||||
is FirTypeAlias -> classifierStorage.registerTypeAlias(scriptStatement, irScript)
|
||||
else -> {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
|
||||
class SimpleClass(val s: String) {
|
||||
fun foo() = s
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<!TOPLEVEL_TYPEALIASES_ONLY!>typealias TopLevelInScript = String<!>
|
||||
|
||||
class C {
|
||||
<!TOPLEVEL_TYPEALIASES_ONLY!>typealias NestedInClass = String<!>
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
<!TOPLEVEL_TYPEALIASES_ONLY!>typealias Local = String<!>
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
typealias TopLevelInScript = String
|
||||
|
||||
class C {
|
||||
|
||||
Reference in New Issue
Block a user