Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,10 @@ extends DeclarationMsg(OverrideErrorID), NoDisambiguation:

class ForwardReferenceExtendsOverDefinition(value: Symbol, definition: Symbol)(using Context)
extends ReferenceMsg(ForwardReferenceExtendsOverDefinitionID) {
def msg(using Context) = i"${definition.name} is a forward reference extending over the definition of ${value.name}"
extension (sym: Symbol) def srcLine = sym.line + 1
def msg(using Context) = i"${definition.name}${
if value != definition then s" (defined on L${definition.srcLine})" else ""
} is a forward reference extending over the definition of ${value.name} (on L${value.srcLine})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Have you considered spelling out "line X" rather than the shortcut "LX"? Perhaps it's little less cognitive power required while trying to understand the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was probably influenced by github's library/src/scala/App.scala#L13 and in the heat of the moment I wanted to make the "extra" info as brief as possible. The word line is a Java indent. The message is already verbose, so (on line 11) is unnoticed at the end of the line, but at the beginning, it pushes the "semantic text" to one's peripheral vision.

But repeating the name is usually redundant. The message could read:

forward reference to g (defined on line 12) extends over the definition of x (on line 11)

I'll try that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a vast improvement at little cost. English gerund is an indent.

-   |                 g (defined on L17) is a forward reference extending over the definition of x (on L16)
+   |                 forward reference to g (defined on line 17) extends over the definition of x (on line 16)

Do you think it should say:

(defined on line 17 counting from 1 instead of 0)

just kidding.


def explain(using Context) =
i"""|${definition.name} is used before you define it, and the definition of ${value.name}
Expand Down
30 changes: 30 additions & 0 deletions tests/neg/i14401.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- [E039] Reference Error: tests/neg/i14401.scala:6:17 -----------------------------------------------------------------
6 | def f: Int = x; // error
| ^
| x is a forward reference extending over the definition of x (on L7)
|
| longer explanation available when compiling with `-explain`
-- [E039] Reference Error: tests/neg/i14401.scala:10:17 ----------------------------------------------------------------
10 | def f: Int = g; // error
| ^
| g (defined on L12) is a forward reference extending over the definition of x (on L11)
|
| longer explanation available when compiling with `-explain`
-- [E039] Reference Error: tests/neg/i14401.scala:15:17 ----------------------------------------------------------------
15 | def f: Int = g; // error
| ^
| g (defined on L17) is a forward reference extending over the definition of x (on L16)
|
| longer explanation available when compiling with `-explain`
-- [E039] Reference Error: tests/neg/i14401.scala:31:20 ----------------------------------------------------------------
31 | } yield a + 27 // error
| ^
| ec (defined on L33) is a forward reference extending over the definition of z (on L29)
|
| longer explanation available when compiling with `-explain`
-- [E039] Reference Error: tests/neg/i14401.scala:41:28 ----------------------------------------------------------------
41 | class NotUsed {val xs = args} // error
| ^^^^
| args (defined on L44) is a forward reference extending over the definition of dummy (on L42)
|
| longer explanation available when compiling with `-explain`
46 changes: 46 additions & 0 deletions tests/neg/i14401.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
object Test {
def f: Int = x;
val x: Int = f;

{
def f: Int = x; // error
val x: Int = f;
}
{
def f: Int = g; // error
val x: Int = f;
def g: Int = x;
}
{
def f: Int = g; // error
var x: Int = f;
def g: Int = x;
}
{
def f: Int = g;
Console.println("foo");
def g: Int = f;
}
{
import scala.concurrent.{ExecutionContext, Future}, ExecutionContext.Implicits

def foo: Future[Int] = {
val fInt = Future.successful(42)
val z = for {
a <- fInt
} yield a + 27 // error

implicit val ec: ExecutionContext = Implicits.global
z
}
foo
}
}
object MyApp {
def main(args: Array[String]) = {
class NotUsed {val xs = args} // error
val dummy = false
// oops, shadows the parameter
def args = Seq("a","b","c")
}
}
10 changes: 0 additions & 10 deletions tests/untried/neg/forward.check

This file was deleted.

24 changes: 0 additions & 24 deletions tests/untried/neg/forward.scala

This file was deleted.

Loading