K2 Scripting: Skip base class params from resolution scope

The base class in scripting considered obsolete and therefore supported
via some ad-hoc mechanisms. In particular parameters to the base class
c-tor are passed via script provided properties. But in combination
with the resolution logic, this leads to issues described in KT-60452
This commits filters out such parameters from script resolution
scope and avoids this problem for now.
Bot it should be noted that proper diagnostics for properties shadowing
should still be implemented - see #KT-65809
#KT-60452 fixed
This commit is contained in:
Ilya Chernikov
2024-02-14 16:49:48 +01:00
committed by Space Team
parent 49559d2a5a
commit 9037975758
33 changed files with 138 additions and 58 deletions
@@ -534,7 +534,11 @@ class BodyResolveContext(
val statics = base
.addNonLocalScopeIfNotNull(towerElementsForScript.staticScope)
val parameterScope = owner.parameters.fold(FirLocalScope(holder.session)) { scope, parameter ->
val parameterScope = owner.parameters.filter {
// for compatibility with old script resolve, the parameters that implicitly copied from the base class c-tor are ignored here
// this quirk should be removed after removing base class support (KT-60449)
it.origin != FirDeclarationOrigin.ScriptCustomization.ParameterFromBaseClass
}.fold(FirLocalScope(holder.session)) { scope, parameter ->
scope.storeVariable(parameter, holder.session)
}
@@ -555,7 +555,9 @@ open class FirDeclarationsResolveTransformer(
.transformOtherChildren(transformer, ResolutionMode.ContextIndependent)
context.storeVariable(variable, session)
if (variable.origin != FirDeclarationOrigin.ScriptCustomization.Parameter) {
if (variable.origin != FirDeclarationOrigin.ScriptCustomization.Parameter &&
variable.origin != FirDeclarationOrigin.ScriptCustomization.ParameterFromBaseClass)
{
// script parameters should not be added to CFG to avoid graph building compilations
dataFlowAnalyzer.exitLocalVariableDeclaration(variable, hadExplicitType)
}
@@ -54,6 +54,7 @@ sealed class FirDeclarationOrigin(
object Default : ScriptCustomization(FirScriptCustomizationKind.DEFAULT)
object ResultProperty : ScriptCustomization(FirScriptCustomizationKind.RESULT_PROPERTY)
object Parameter : ScriptCustomization(FirScriptCustomizationKind.PARAMETER)
object ParameterFromBaseClass : ScriptCustomization(FirScriptCustomizationKind.PARAMETER_FROM_BASE_CLASS)
}
class Plugin(val key: GeneratedDeclarationKey) : FirDeclarationOrigin(displayName = "Plugin[$key]", generated = true)
@@ -11,5 +11,6 @@ const val SCRIPT_RECEIVER_NAME_PREFIX = "\$script_receiver"
enum class FirScriptCustomizationKind {
DEFAULT,
RESULT_PROPERTY,
PARAMETER
PARAMETER,
PARAMETER_FROM_BASE_CLASS, // TODO: remove after fixing KT-60449
}