Skip to content

Fix off-by-one error in forward reference checking #1997

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 2 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ object messages {
|
|Define `${definition.name}` before it is used,
|or move the definition of `${value.name}` so it does not appear between
|the declartion of `${definition.name}` and its use,
|the declaration of `${definition.name}` and its use,
|or define `${value.name}` as lazy.
|""".stripMargin
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ class RefChecks extends MiniPhase { thisTransformer =>
val sym = tree.symbol
if (sym.exists && sym.owner.isTerm && !sym.is(Lazy))
currentLevel.levelAndIndex.get(sym) match {
case Some((level, symIdx)) if symIdx < level.maxIndex =>
case Some((level, symIdx)) if symIdx <= level.maxIndex =>
ctx.error(ForwardReferenceExtendsOverDefinition(sym, level.refSym), level.refPos)
case _ =>
}
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i1992.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Test {
def main(args: Array[String]) = {
val x: Int => Unit =
y => println(x) // error: `x` is a forward reference
implicit val z: String => Unit =
y => println(implicitly[String => Unit]) // error: `z` is a forward reference
}
}

7 changes: 7 additions & 0 deletions tests/neg/i2005.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

object Test {
val a = 42
def main(args: Array[String]) = {
val a: Int = a // error
}
}