-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Context for constructor error is outer context #9893
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
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
val cls = owner.enclosingSubClass | ||
if (!cls.exists) | ||
if !cls.exists then | ||
val encl = if !ctx.owner.isConstructor then ctx else ctx.outersIterator.dropWhile(_.owner.isConstructor).next() |
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 code does not handle secondary constructors. Will something like the following work?
val encl = if !ctx.owner.isConstructor then ctx else ctx.outersIterator.dropWhile(_.owner.isConstructor).next() | |
val encl = if ctx.owner.isPrimaryConstructor then ctx.owner.enclosingClass.owner.enclosingClass else ctx |
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 expressions are the same, as the next outer context which is not owned by a ctor will be the correct enclosing class; also, both tests will discover an enclosing package symbol. I prefer your suggestion, which avoids an iterator -- although I almost talked myself out of it: the average view is that we seem to be skipping our class for the enclosing class; though from a context perspective, we're really just pushing out to the true enclosing class. (The context of expressions to super constructors is always confusing.) However, it seems isConstructor
works here, also for secondaries; outersIterator
would just plow through a couple more contexts in that case.
This change is a smallish tweak, but a good opportunity to take a look at scala 3 contexts...
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.
Sorry, I wasn't clear. I meant that in a secondary constructor, we might not want to go to the outer class --- as the current class itself could extend the related class.
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.
It's obvious when you put it that way.
Dotty CI claims the test output does not match the check file, but it looks the same to me. At this point, I wish the test rig would just display the diff (as partest learned to do, eventually). Edit: maybe the way I naively changed the first line of the interpolation caused the VBARs to drop out? But it works locally... |
Running |
Thanks @smarter I've stuck up a post-it note. The test passes locally. When I munge the test, the "actual output" in sbt doesn't show the Soon I'll push an update and see what happens! I can't wait! |
Just |
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.
LGTM 🎉
I came back for |
Fixes #7709