From 2da43052f0f0ff04c500c074ee429a6d713a6a2d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 18 Feb 2017 13:12:26 +0100 Subject: Fix off-by-one error in forward reference checking --- .../src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 2 +- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 2 +- tests/neg/i1992.scala | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i1992.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 94611e10d..9318ad8c6 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index eab91701b..7c573d23c 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -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 _ => } diff --git a/tests/neg/i1992.scala b/tests/neg/i1992.scala new file mode 100644 index 000000000..818b46771 --- /dev/null +++ b/tests/neg/i1992.scala @@ -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 + } +} + -- cgit v1.2.3