Skip to content

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

Merged
merged 1 commit into from
Nov 5, 2020

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Sep 27, 2020

Fixes #7709

Copy link
Member

@dottybot dottybot left a 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()
Copy link
Contributor

@liufengyun liufengyun Sep 29, 2020

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?

Suggested change
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

Copy link
Contributor Author

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...

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@som-snytt
Copy link
Contributor Author

som-snytt commented Sep 29, 2020

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...

@smarter
Copy link
Member

smarter commented Sep 29, 2020

Running testCompilation --update-checkfiles tests/neg/i7709.scala should fix the checkfile.

@som-snytt
Copy link
Contributor Author

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 | on the LHS of the message output, although it is present as usual in the .check.out. I did verify my sha is pushed.

Soon I'll push an update and see what happens! I can't wait!

@som-snytt
Copy link
Contributor Author

Just --update-checkfiles and squash. Previous feedback had been addressed.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@liufengyun liufengyun merged commit ef3acdb into scala:master Nov 5, 2020
@som-snytt som-snytt deleted the issue/7709 branch November 5, 2020 19:55
@som-snytt
Copy link
Contributor Author

I came back for --update-checkfiles because no autocomplete and partest --update-check.

@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access message misidentifies enclosing template
5 participants