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
|
trace: BindingTrace
|
||||||
) : LazyClassMemberScope(resolveSession, declarationProvider, scriptDescriptor, trace) {
|
) : 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 {
|
private val scriptPrimaryConstructor: () -> ClassConstructorDescriptorImpl? = resolveSession.storageManager.createNullableLazyValue {
|
||||||
val baseClass = scriptDescriptor.baseClassDescriptor()
|
val baseClass = scriptDescriptor.baseClassDescriptor()
|
||||||
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
|
val baseConstructorDescriptor = baseClass?.unsubstitutedPrimaryConstructor
|
||||||
@@ -82,9 +91,11 @@ class LazyScriptClassMemberScope(
|
|||||||
return constructor
|
return constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getVariableNames() = _variableNames
|
||||||
|
|
||||||
override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
|
override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
|
||||||
super.getNonDeclaredProperties(name, result)
|
super.getNonDeclaredProperties(name, result)
|
||||||
if (scriptDescriptor.resultFieldName() == name.asString()) {
|
if (scriptDescriptor.resultFieldName() == name) {
|
||||||
scriptDescriptor.resultValue?.let {
|
scriptDescriptor.resultValue?.let {
|
||||||
result.add(it)
|
result.add(it)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -83,7 +83,7 @@ class LazyScriptDescriptor(
|
|||||||
return if (type != null && !type.isUnit() && !type.isNothing()) {
|
return if (type != null && !type.isUnit() && !type.isNothing()) {
|
||||||
resultFieldName()?.let {
|
resultFieldName()?.let {
|
||||||
ReplResultPropertyDescriptor(
|
ReplResultPropertyDescriptor(
|
||||||
Name.identifier(it),
|
it,
|
||||||
type,
|
type,
|
||||||
this.thisAsReceiverParameter,
|
this.thisAsReceiverParameter,
|
||||||
this,
|
this,
|
||||||
@@ -93,11 +93,11 @@ class LazyScriptDescriptor(
|
|||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resultFieldName(): String? {
|
fun resultFieldName(): Name? {
|
||||||
// TODO: implement robust REPL/script selection
|
// TODO: implement robust REPL/script selection
|
||||||
val replSnippetId =
|
val replSnippetId =
|
||||||
scriptInfo.script.getUserData(ScriptPriorities.PRIORITY_KEY)?.toString()
|
scriptInfo.script.getUserData(ScriptPriorities.PRIORITY_KEY)?.toString()
|
||||||
return if (replSnippetId != null) {
|
val identifier = if (replSnippetId != null) {
|
||||||
// assuming repl
|
// assuming repl
|
||||||
scriptCompilationConfiguration()[ScriptCompilationConfiguration.repl.resultFieldPrefix]?.takeIf { it.isNotBlank() }?.let {
|
scriptCompilationConfiguration()[ScriptCompilationConfiguration.repl.resultFieldPrefix]?.takeIf { it.isNotBlank() }?.let {
|
||||||
"$it$replSnippetId"
|
"$it$replSnippetId"
|
||||||
@@ -105,6 +105,7 @@ class LazyScriptDescriptor(
|
|||||||
} else {
|
} else {
|
||||||
scriptCompilationConfiguration()[ScriptCompilationConfiguration.resultField]?.takeIf { it.isNotBlank() }
|
scriptCompilationConfiguration()[ScriptCompilationConfiguration.resultField]?.takeIf { it.isNotBlank() }
|
||||||
}
|
}
|
||||||
|
return identifier?.let { Name.identifier(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val sourceElement = scriptInfo.script.toSourceElement()
|
private val sourceElement = scriptInfo.script.toSourceElement()
|
||||||
|
|||||||
Reference in New Issue
Block a user