-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix init checker on secondary constructor parameter access #13776
Fix init checker on secondary constructor parameter access #13776
Conversation
Fixed! Please have another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, LGTM 🎉
@@ -652,6 +652,16 @@ object Semantic { | |||
} | |||
|
|||
def callConstructor(ctor: Symbol, args: List[ArgInfo], source: Tree): Contextual[Result] = log("call " + ctor.show + ", args = " + args, printer, (_: Result).show) { | |||
// init "fake" param fields for the secondary constructor | |||
def addEnvToRef(env: Env, ref: Ref) = { | |||
val ctorDef = ctor.defTree.asInstanceOf[DefDef] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: We can avoid ctor.defTree.asInstanceOf[DefDef]
by passing it from call sites --- there we already have ddef
.
Maybe rename addEnvToRef
to something like addParamAsField
to be more clear?
def this(b: B, m: Int) = { | ||
this(b) | ||
def foo = m // resolved to parameter `m` | ||
class C { foo } // resolved to parameter `m`, as hidden field of `A` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this comment belong on the previous line? I don't see how it applies to class C
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to foo
here will cause the interpreter to look up m
(and from the PR's changes, find m
as a hidden field of A
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it, thanks.
2e3d0fc
to
0bafae2
Compare
- Insert the parameters of the secondary constructor into the `Objekt` of `thisV`, so that they can be looked up when it is referenced. - Add tests
8f67d07
to
1971882
Compare
@liufengyun @olhotak I think it is ready, please merge if it looks OK. |
Insert the parameters of the secondary constructor into the
Objekt
ofthisV
, so that they can be looked up when it isreferenced.
An example is provided as a test file.
Upon calling a secondary constructor, we add the
parameters into the cache as if they were fields of
the constructed object (similar to a primary constructor).
Due to the actual fields referenced being resolved to
fully qualified names (but references to parameters are not),
we also change the
accessLocal
logic to look at theobject cache first, if we are in a Constructor context.