aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorEnno <enno@runne.net>2017-02-14 12:52:20 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-02-14 12:52:20 +0100
commit47901c09885f8931d82a3bbc469985a50f790091 (patch)
tree4b478d0235a3cccb4416e9c50bdd9315b3e6f1e7 /compiler/src/dotty/tools/dotc
parentb29783237c03ade1dd19cc564170c7a87d7b8b84 (diff)
downloaddotty-47901c09885f8931d82a3bbc469985a50f790091.tar.gz
dotty-47901c09885f8931d82a3bbc469985a50f790091.tar.bz2
dotty-47901c09885f8931d82a3bbc469985a50f790091.zip
Ennru forward reference error (#1973)
* Change 'forward reference extending over the definition' to Message * Change 'forward reference extending over the definition' to Message * pesky file should not be included * Change 'forward reference extending over the definition' to Message (test case)
Diffstat (limited to 'compiler/src/dotty/tools/dotc')
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala19
-rw-r--r--compiler/src/dotty/tools/dotc/typer/RefChecks.scala4
2 files changed, 21 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index c25c49597..4d61f21cf 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -1034,4 +1034,23 @@ object messages {
|"""
}
+ case class ForwardReferenceExtendsOverDefinition(value: Symbol, definition: Symbol)(implicit ctx: Context)
+ extends Message(39) {
+ val kind = "Reference"
+ val msg = hl"`${definition.name}` is a forward reference extending over the definition of `${value.name}`"
+
+ val explanation =
+ hl"""|`${definition.name}` is used before you define it, and the definition of `${value.name}`
+ |appears between that use and the definition of `${definition.name}`.
+ |
+ |Forward references are allowed only, if there are no value definitions between
+ |the reference and the referred method definition.
+ |
+ |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,
+ |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 ada53047a..eab91701b 100644
--- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -767,6 +767,7 @@ import RefChecks._
class RefChecks extends MiniPhase { thisTransformer =>
import tpd._
+ import reporting.diagnostic.messages.ForwardReferenceExtendsOverDefinition
override def phaseName: String = "refchecks"
@@ -789,8 +790,7 @@ class RefChecks extends MiniPhase { thisTransformer =>
if (sym.exists && sym.owner.isTerm && !sym.is(Lazy))
currentLevel.levelAndIndex.get(sym) match {
case Some((level, symIdx)) if symIdx < level.maxIndex =>
- ctx.debuglog("refsym = " + level.refSym)
- ctx.error(s"forward reference extends over definition of $sym", level.refPos)
+ ctx.error(ForwardReferenceExtendsOverDefinition(sym, level.refSym), level.refPos)
case _ =>
}
tree