Skip to content

Commit 723e4b4

Browse files
committed
Fix off-by-one error in forward reference checking
1 parent 1946b36 commit 723e4b4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ object messages {
10551055
|
10561056
|Define `${definition.name}` before it is used,
10571057
|or move the definition of `${value.name}` so it does not appear between
1058-
|the declartion of `${definition.name}` and its use,
1058+
|the declaration of `${definition.name}` and its use,
10591059
|or define `${value.name}` as lazy.
10601060
|""".stripMargin
10611061
}

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ class RefChecks extends MiniPhase { thisTransformer =>
789789
val sym = tree.symbol
790790
if (sym.exists && sym.owner.isTerm && !sym.is(Lazy))
791791
currentLevel.levelAndIndex.get(sym) match {
792-
case Some((level, symIdx)) if symIdx < level.maxIndex =>
792+
case Some((level, symIdx)) if symIdx <= level.maxIndex =>
793793
ctx.error(ForwardReferenceExtendsOverDefinition(sym, level.refSym), level.refPos)
794794
case _ =>
795795
}

tests/neg/i1992.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def main(args: Array[String]) = {
3+
val x: Int => Unit =
4+
y => println(x) // error: `x` is a forward reference
5+
implicit val z: String => Unit =
6+
y => println(implicitly[String => Unit]) // error: `z` is a forward reference
7+
}
8+
}
9+

0 commit comments

Comments
 (0)