Skip to content

Improve description of given instances in error messages #11067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
else if (sym.isType) "type"
else if (sym.isGetter) "getter"
else if (sym.isSetter) "setter"
else if sym.is(Param) then "parameter"
else if sym.is(Given) then "given instance"
else if (flags.is(Lazy)) "lazy value"
else if (flags.is(Mutable)) "variable"
else if (sym.isClassConstructor && sym.isPrimaryConstructor) "primary constructor"
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i9014.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
|
| given_Bar
|
| But method given_Bar does not match type Bar.
| But given instance given_Bar does not match type Bar.
8 changes: 4 additions & 4 deletions tests/neg/abstract-givens.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
-- Error: tests/neg/abstract-givens.scala:8:8 --------------------------------------------------------------------------
8 | given y(using Int): String = summon[Int].toString * 22 // error
| ^
| error overriding method y in trait T of type (using x$1: Int): String;
| method y of type (using x$1: Int): String cannot override final member method y in trait T
| error overriding given instance y in trait T of type (using x$1: Int): String;
| given instance y of type (using x$1: Int): String cannot override final member given instance y in trait T
-- Error: tests/neg/abstract-givens.scala:9:8 --------------------------------------------------------------------------
9 | given z[T](using T): Seq[T] = List(summon[T]) // error
| ^
| error overriding method z in trait T of type [T](using x$1: T): List[T];
| method z of type [T](using x$1: T): Seq[T] has incompatible type
| error overriding given instance z in trait T of type [T](using x$1: T): List[T];
| given instance z of type [T](using x$1: T): Seq[T] has incompatible type
2 changes: 1 addition & 1 deletion tests/neg/exports.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-- Error: tests/neg/exports.scala:25:21 --------------------------------------------------------------------------------
25 | export printUnit.bitmap // error: no eligible member
| ^
| non-private method bitmap in class Copier refers to private value printUnit
| non-private given instance bitmap in class Copier refers to private value printUnit
| in its type signature => Copier.this.printUnit.bitmap$
-- [E120] Naming Error: tests/neg/exports.scala:23:33 ------------------------------------------------------------------
23 | export printUnit.{stat => _, _} // error: double definition
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i11066.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i11066.scala:15:37 ---------------------------------------------------------------------------------
15 |val x = Greeter.greet("Who's there?") // error
| ^
|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
15 changes: 15 additions & 0 deletions tests/neg/i11066.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class PreferredPrompt(val preference: String)
object Greeter:
def greet(name: String)(using prompt: PreferredPrompt) =
println(s"Welcome, $name. The system is ready.")
println(prompt.preference)
object JillsPrefs:
given jillsPrompt: PreferredPrompt =
PreferredPrompt("Your wish> ")
object JoesPrefs:
given joesPrompt: PreferredPrompt =
PreferredPrompt("relax> ")

import JillsPrefs.jillsPrompt
import JoesPrefs.joesPrompt
val x = Greeter.greet("Who's there?") // error
2 changes: 1 addition & 1 deletion tests/neg/i9014.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
|
| Bar.given_Bar
|
| But method given_Bar in object Bar does not match type Bar.
| But given instance given_Bar in object Bar does not match type Bar.
2 changes: 1 addition & 1 deletion tests/neg/missing-implicit2.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Error: tests/neg/missing-implicit2.scala:10:18 ----------------------------------------------------------------------
10 | f(using xFromY) // error
| ^
| no implicit argument of type Y was found for parameter y of method xFromY
| no implicit argument of type Y was found for parameter y of given instance xFromY
|
| The following import might fix the problem:
|
Expand Down
2 changes: 1 addition & 1 deletion tests/run-staging/i7142.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ object Test {
try run {returning('{ { (x: Int) => ${ throwReturn('x) }} apply 0 })}
catch {
case ex: dotty.tools.dotc.reporting.Diagnostic.Error =>
assert(ex.getMessage == "While expanding a macro, a reference to value x was used outside the scope where it was defined", ex.getMessage)
assert(ex.getMessage == "While expanding a macro, a reference to parameter x was used outside the scope where it was defined", ex.getMessage)
}
}