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:
Ilya Muradyan
2020-06-02 12:35:13 +03:00
committed by Ilya Chernikov
parent 6da22414dc
commit 262e21fcbc
2 changed files with 16 additions and 4 deletions
@@ -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)
}
@@ -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()