Skip to content

Commit b58b22e

Browse files
committed
Unwrap NamedType in type mismatch error message
Makes the error message print the actual type instead of scary internal representation. E.g: `Foo(Test.f)` => `Foo`
1 parent 5192eac commit b58b22e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,12 @@ object messages {
293293
)
294294
}
295295

296-
ex"$selected `$name` is not a member of $site$closeMember"
296+
val siteType = site match {
297+
case tp: NamedType => tp.info
298+
case tp => tp
299+
}
300+
301+
ex"$selected `$name` is not a member of $siteType$closeMember"
297302
}
298303

299304
val explanation = ""

tests/repl/errmsgs.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
7777
-- [E008] Member Not Found Error: <console>:4:59 -------------------------------
7878
4 |class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
7979
| ^^^^^^^^
80-
| value `barr` is not a member of Foo(foo) - did you mean `foo.bar`?
80+
| value `barr` is not a member of Foo - did you mean `foo.bar`?
8181
scala> val x: List[Int] = "foo" :: List(1)
8282
-- [E007] Type Mismatch Error: <console>:4:19 ----------------------------------
8383
4 |val x: List[Int] = "foo" :: List(1)

tests/repl/imports.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ scala> import util.foo.bar
2424
-- [E008] Member Not Found Error: <console>:8:12 -------------------------------
2525
8 |import util.foo.bar
2626
| ^^^^^^^^
27-
| value `foo` is not a member of util.type - did you mean `util.Left`?
27+
| value `foo` is not a member of util - did you mean `util.Left`?
2828
scala> :quit

0 commit comments

Comments
 (0)