Skip to content

Commit b50372e

Browse files
Merge pull request #11067 from dotty-staging/fix-#11066
Improve description of given instances in error messages
2 parents b43778f + d6b9223 commit b50372e

File tree

9 files changed

+30
-9
lines changed

9 files changed

+30
-9
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
426426
else if (sym.isType) "type"
427427
else if (sym.isGetter) "getter"
428428
else if (sym.isSetter) "setter"
429+
else if sym.is(Param) then "parameter"
430+
else if sym.is(Given) then "given instance"
429431
else if (flags.is(Lazy)) "lazy value"
430432
else if (flags.is(Mutable)) "variable"
431433
else if (sym.isClassConstructor && sym.isPrimaryConstructor) "primary constructor"

tests/neg-macros/i9014.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
|
88
| given_Bar
99
|
10-
| But method given_Bar does not match type Bar.
10+
| But given instance given_Bar does not match type Bar.

tests/neg/abstract-givens.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
-- Error: tests/neg/abstract-givens.scala:8:8 --------------------------------------------------------------------------
66
8 | given y(using Int): String = summon[Int].toString * 22 // error
77
| ^
8-
| error overriding method y in trait T of type (using x$1: Int): String;
9-
| method y of type (using x$1: Int): String cannot override final member method y in trait T
8+
| error overriding given instance y in trait T of type (using x$1: Int): String;
9+
| given instance y of type (using x$1: Int): String cannot override final member given instance y in trait T
1010
-- Error: tests/neg/abstract-givens.scala:9:8 --------------------------------------------------------------------------
1111
9 | given z[T](using T): Seq[T] = List(summon[T]) // error
1212
| ^
13-
| error overriding method z in trait T of type [T](using x$1: T): List[T];
14-
| method z of type [T](using x$1: T): Seq[T] has incompatible type
13+
| error overriding given instance z in trait T of type [T](using x$1: T): List[T];
14+
| given instance z of type [T](using x$1: T): Seq[T] has incompatible type

tests/neg/exports.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
-- Error: tests/neg/exports.scala:25:21 --------------------------------------------------------------------------------
1111
25 | export printUnit.bitmap // error: no eligible member
1212
| ^
13-
| non-private method bitmap in class Copier refers to private value printUnit
13+
| non-private given instance bitmap in class Copier refers to private value printUnit
1414
| in its type signature => Copier.this.printUnit.bitmap$
1515
-- [E120] Naming Error: tests/neg/exports.scala:23:33 ------------------------------------------------------------------
1616
23 | export printUnit.{stat => _, _} // error: double definition

tests/neg/i11066.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i11066.scala:15:37 ---------------------------------------------------------------------------------
2+
15 |val x = Greeter.greet("Who's there?") // error
3+
| ^
4+
|ambiguous implicit arguments: both given instance joesPrompt in object JoesPrefs and given instance jillsPrompt in object JillsPrefs match type PreferredPrompt of parameter prompt of method greet in object Greeter

tests/neg/i11066.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class PreferredPrompt(val preference: String)
2+
object Greeter:
3+
def greet(name: String)(using prompt: PreferredPrompt) =
4+
println(s"Welcome, $name. The system is ready.")
5+
println(prompt.preference)
6+
object JillsPrefs:
7+
given jillsPrompt: PreferredPrompt =
8+
PreferredPrompt("Your wish> ")
9+
object JoesPrefs:
10+
given joesPrompt: PreferredPrompt =
11+
PreferredPrompt("relax> ")
12+
13+
import JillsPrefs.jillsPrompt
14+
import JoesPrefs.joesPrompt
15+
val x = Greeter.greet("Who's there?") // error

tests/neg/i9014.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
|
77
| Bar.given_Bar
88
|
9-
| But method given_Bar in object Bar does not match type Bar.
9+
| But given instance given_Bar in object Bar does not match type Bar.

tests/neg/missing-implicit2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/neg/missing-implicit2.scala:10:18 ----------------------------------------------------------------------
22
10 | f(using xFromY) // error
33
| ^
4-
| no implicit argument of type Y was found for parameter y of method xFromY
4+
| no implicit argument of type Y was found for parameter y of given instance xFromY
55
|
66
| The following import might fix the problem:
77
|

tests/run-staging/i7142.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ object Test {
88
try run {returning('{ { (x: Int) => ${ throwReturn('x) }} apply 0 })}
99
catch {
1010
case ex: dotty.tools.dotc.reporting.Diagnostic.Error =>
11-
assert(ex.getMessage == "While expanding a macro, a reference to value x was used outside the scope where it was defined", ex.getMessage)
11+
assert(ex.getMessage == "While expanding a macro, a reference to parameter x was used outside the scope where it was defined", ex.getMessage)
1212
}
1313
}

0 commit comments

Comments
 (0)