Skip to content

Fix #2117: bug in typechecking super prefix with invalid enclosing class #2118

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
Mar 20, 2017

Conversation

abeln
Copy link
Contributor

@abeln abeln commented Mar 17, 2017

When typechecking

class A { C.super.foo() }

If C isn't an enclosing class, the compiler was throwing because of an
unguarded pattern match.

Fix the issue by checking for ErrorType.

Tested:
Verified that the example above no longer throws.

case p :: q :: _ =>
errorType("ambiguous parent class qualifier", tree.pos)
qual.tpe match {
case err: ErrorType => untpd.cpy.Super(tree)(qual, mix).withType(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this necessary, or can I just do tree.withType(err)?
In general, when I should I be using the tree copier?

Copy link
Contributor

Choose a reason for hiding this comment

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

Tree copier provides structural sharing and is used when you think that the tree might stay the same after your changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. In this case, would it be ok/better to do tree.withType(err)?

Copy link
Contributor Author

@abeln abeln left a comment

Choose a reason for hiding this comment

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

What would be a good place to unit tests for this?

@DarkDimius
Copy link
Contributor

Thanks for the contribution!

What would be a good place to unit tests for this?

tests/neg/i2117.scala.

Would you also kindly update commit message to "Fix #2117: ..."

@abeln abeln changed the title Fix bug in typechecking super prefix with invalid enclosing class Fix #2117: bug in typechecking super prefix with invalid enclosing class Mar 17, 2017
@abeln
Copy link
Contributor Author

abeln commented Mar 17, 2017

Added the test. PTAL.
What's the significance of "i" in "i2117"? (i.e. what's the naming convention, given that other files in that directory don't follow the same style).

When typechecking

class A {
  C.super.foo()
}

If C isn't an enclosing class, the compiler was throwing because of an
unguarded pattern match.

Fix the issue by checking for ErrorType.

Tested:
Verified that the example above no longer throws.
Added a test.
@smarter
Copy link
Member

smarter commented Mar 17, 2017

"i" means issue and refers to an issue number on https://github.com/lampepfl/dotty/issues. "t" means ticket and refers to an issue number on scalac bug tracker (because the test was imported from scalac): https://issues.scala-lang.org/secure/Dashboard.jspa

@abeln
Copy link
Contributor Author

abeln commented Mar 19, 2017

Friendly ping @DarkDimius @smarter @felixmulder
Does this look good or would you like something changed? Thanks!

@DarkDimius
Copy link
Contributor

@abeln, thank you for pinging. It's good as is.
LGTM

@DarkDimius DarkDimius merged commit 53b808f into scala:master Mar 20, 2017
@abeln abeln deleted the super-bug branch March 31, 2017 13:22
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.

3 participants