Import scope of the imported script
#KT-34178
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ class MainKtsIT {
|
||||
|
||||
runWithK2JVMCompiler(
|
||||
"$TEST_DATA_ROOT/import-test.main.kts",
|
||||
listOf("Hi from common", "Hi from middle", "sharedVar == 5"),
|
||||
listOf("Hi from common", "Hi from middle", "Hi from main", "sharedVar == 5"),
|
||||
classpath = listOf(mainKtsJar)
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ fun evalFile(scriptFile: File, cacheDir: File? = null): ResultWithDiagnostics<Ev
|
||||
|
||||
|
||||
const val TEST_DATA_ROOT = "libraries/tools/kotlin-main-kts-test/testData"
|
||||
val OUT_FROM_IMPORT_TEST = listOf("Hi from common", "Hi from middle", "sharedVar == 5")
|
||||
val OUT_FROM_IMPORT_TEST = listOf("Hi from common", "Hi from middle", "Hi from main", "sharedVar == 5")
|
||||
|
||||
|
||||
class MainKtsTest {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
|
||||
var sharedVar = 2
|
||||
|
||||
println("Hi from common")
|
||||
class SharedClass(val msg: String)
|
||||
|
||||
object SharedObject {
|
||||
val greeting = "Hi"
|
||||
}
|
||||
|
||||
println("${SharedObject.greeting} from common")
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
|
||||
sharedVar *= 2
|
||||
|
||||
println("Hi from middle")
|
||||
val from = SharedClass("from")
|
||||
|
||||
println("${SharedObject.greeting} ${from.msg} middle")
|
||||
|
||||
@@ -4,4 +4,5 @@
|
||||
|
||||
sharedVar = sharedVar + 1
|
||||
|
||||
println("${SharedObject.greeting} ${from.msg} main")
|
||||
println("sharedVar == $sharedVar")
|
||||
|
||||
+5
-2
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
|
||||
import org.jetbrains.kotlin.resolve.AllUnderImportScope
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -34,6 +35,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassMemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.addImportingScope
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition
|
||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDependenciesProvider
|
||||
@@ -43,7 +45,6 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.io.File
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.script.experimental.api.*
|
||||
@@ -180,7 +181,7 @@ class LazyScriptDescriptor(
|
||||
|
||||
val localFS by lazy {
|
||||
val fileManager = VirtualFileManager.getInstance()
|
||||
fileManager.getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
fileManager.getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
}
|
||||
val psiManager by lazy { PsiManager.getInstance(scriptInfo.script.project) }
|
||||
|
||||
@@ -285,6 +286,8 @@ class LazyScriptDescriptor(
|
||||
true,
|
||||
receiverClassDescriptor.thisAsReceiverParameter,
|
||||
LexicalScopeKind.CLASS_MEMBER_SCOPE
|
||||
).addImportingScope(
|
||||
AllUnderImportScope.create(receiverClassDescriptor, emptyList())
|
||||
)
|
||||
}
|
||||
outerScope
|
||||
|
||||
Reference in New Issue
Block a user