Add overload to comply with the contract
Method getVariableNames() should return all variable names, but in the inherited implementation it doesn't return resX names which represent result fields.
This commit is contained in:
committed by
Ilya Chernikov
parent
6da22414dc
commit
262e21fcbc
+12
-1
@@ -25,6 +25,15 @@ class LazyScriptClassMemberScope(
|
||||
trace: BindingTrace
|
||||
) : LazyClassMemberScope(resolveSession, declarationProvider, scriptDescriptor, trace) {
|
||||
|
||||
private val _variableNames: MutableSet<Name>
|
||||
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
super.getVariableNames().apply {
|
||||
scriptDescriptor.resultFieldName()?.let {
|
||||
add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val scriptPrimaryConstructor: () -> ClassConstructorDescriptorImpl? = resolveSession.storageManager.createNullableLazyValue {
|
||||
val baseClass = scriptDescriptor.baseClassDescriptor()
|
||||
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
|
||||
@@ -82,9 +91,11 @@ class LazyScriptClassMemberScope(
|
||||
return constructor
|
||||
}
|
||||
|
||||
override fun getVariableNames() = _variableNames
|
||||
|
||||
override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
|
||||
super.getNonDeclaredProperties(name, result)
|
||||
if (scriptDescriptor.resultFieldName() == name.asString()) {
|
||||
if (scriptDescriptor.resultFieldName() == name) {
|
||||
scriptDescriptor.resultValue?.let {
|
||||
result.add(it)
|
||||
}
|
||||
|
||||
+4
-3
@@ -83,7 +83,7 @@ class LazyScriptDescriptor(
|
||||
return if (type != null && !type.isUnit() && !type.isNothing()) {
|
||||
resultFieldName()?.let {
|
||||
ReplResultPropertyDescriptor(
|
||||
Name.identifier(it),
|
||||
it,
|
||||
type,
|
||||
this.thisAsReceiverParameter,
|
||||
this,
|
||||
@@ -93,11 +93,11 @@ class LazyScriptDescriptor(
|
||||
} else null
|
||||
}
|
||||
|
||||
fun resultFieldName(): String? {
|
||||
fun resultFieldName(): Name? {
|
||||
// TODO: implement robust REPL/script selection
|
||||
val replSnippetId =
|
||||
scriptInfo.script.getUserData(ScriptPriorities.PRIORITY_KEY)?.toString()
|
||||
return if (replSnippetId != null) {
|
||||
val identifier = if (replSnippetId != null) {
|
||||
// assuming repl
|
||||
scriptCompilationConfiguration()[ScriptCompilationConfiguration.repl.resultFieldPrefix]?.takeIf { it.isNotBlank() }?.let {
|
||||
"$it$replSnippetId"
|
||||
@@ -105,6 +105,7 @@ class LazyScriptDescriptor(
|
||||
} else {
|
||||
scriptCompilationConfiguration()[ScriptCompilationConfiguration.resultField]?.takeIf { it.isNotBlank() }
|
||||
}
|
||||
return identifier?.let { Name.identifier(it) }
|
||||
}
|
||||
|
||||
private val sourceElement = scriptInfo.script.toSourceElement()
|
||||
|
||||
Reference in New Issue
Block a user