Skip to content
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 #5044: guard against forward references in the TypeTree of New trees #5178

Merged
merged 2 commits into from
Oct 2, 2018

Conversation

Jasper-M
Copy link
Contributor

@Jasper-M Jasper-M commented Sep 28, 2018

The extra dealiasing step also avoids this scalac bug.

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! ☀️

@Jasper-M
Copy link
Contributor Author

Should the following compile?

scala> def foo = { type T = Foo; val a = new T; class Foo }
def foo: Unit

Scalac doesn't think so.

checkUndesiredProperties(sym, tree.pos)
currentLevel.enterReference(sym, tree.pos)
tpe.dealias.foreachPart {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is dealias required?

Copy link
Contributor Author

@Jasper-M Jasper-M Sep 28, 2018

Choose a reason for hiding this comment

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

Without it the second test still fails (crashes). If you would dealias a bit sooner I think def foo = { type T = Foo; val a = new T; class Foo } would also emit an error, like in scalac.

@@ -0,0 +1,8 @@
class I0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would merge the two tests together:

class I0 {
  class I1
  def test0 = {
    val x = new y.I1 // error: `y` is a forward reference extending over the definition of `x`
    val y = new I0
  }

  def test1 = {
    type T = y.I1
    val x = new T // error: `y` is a forward reference extending over the definition of `x`
    val y = new I0
  }
}

type T = i5.I1
val i4 = new T // error: `i5` is a forward reference extending over the definition of `i4`
val i5 = new I0
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is another test with a type lambda

class I0 {
  class I2[T1, T2]
  def test2 = {
    type A[T] = i5.I2[T, String]
    val i4 = new A[Int]
    val i5 = new I0
  }
}

This one currently crashes with Scala 2.12.6 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also add:

  def test3 = {
    val x = new T // error: `T` is a forward reference extending over the definition of `x`
    val y = new I0
    type T = y.I1
  }

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @Jasper-M

@allanrenucci allanrenucci merged commit 935fea7 into scala:master Oct 2, 2018
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