Skip to content

Commit

Permalink
Merge pull request #5178 from Jasper-M/fix/5044
Browse files Browse the repository at this point in the history
Fix #5044: guard against forward references in the TypeTree of New trees
  • Loading branch information
allanrenucci committed Oct 2, 2018
2 parents 8cc445b + 91eaf20 commit 935fea7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,14 @@ class RefChecks extends MiniPhase { thisPhase =>
}

override def transformNew(tree: New)(implicit ctx: Context) = {
val sym = tree.tpe.typeSymbol
val tpe = tree.tpe
val sym = tpe.typeSymbol
checkUndesiredProperties(sym, tree.pos)
currentLevel.enterReference(sym, tree.pos)
tpe.dealias.foreachPart {
case TermRef(_, s: Symbol) => currentLevel.enterReference(s, tree.pos)
case _ =>
}
tree
}
}
Expand Down Expand Up @@ -1643,4 +1648,3 @@ class RefChecks extends MiniPhase { thisPhase =>
}
}
*/

26 changes: 26 additions & 0 deletions tests/neg/i5044.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
}

class I2[T1, T2]
def test2 = {
type A[T] = y.I2[T, String]
val x = new A[Int] // error: `y` is a forward reference extending over the definition of `x`
val y = new I0
}

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

0 comments on commit 935fea7

Please sign in to comment.