Skip to content

Commit 09ace25

Browse files
committed
Give context for code examples to ease understanding
1 parent ab91bd5 commit 09ace25

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -971,25 +971,34 @@ object messages {
971971
val kind = "Syntax"
972972
val msg = hl"""Expected an additional member selection after the keyword ${"this"}"""
973973

974+
val contextCode =
975+
""" trait Outer {
976+
| val member: Int
977+
| type Member
978+
| trait Inner {
979+
| ...
980+
| }
981+
| }"""
982+
974983
val importCode =
975-
"""import MyClass.this.member
976-
|// ^^^^^^^
977-
"""
984+
""" import Outer.this.member
985+
| // ^^^^^^^"""
978986

979987
val typeCode =
980-
"""type T = MyClass.this.Member
981-
|// ^^^^^^^
982-
"""
988+
""" type T = Outer.this.Member
989+
| // ^^^^^^^"""
983990

984991
val explanation =
985992
hl"""|Paths of imports and type selections must not end with the keyword ${"this"}.
986993
|
987-
|Maybe you forgot to select a member of ${"this"}?
994+
|Maybe you forgot to select a member of ${"this"}? As an example, in the
995+
|following context:
996+
|${contextCode}
988997
|
989-
|- Example for a valid import expression using a path
998+
|- this is a valid import expression using a path
990999
|${importCode}
9911000
|
992-
|- Example for a valid type using a path
1001+
|- this is a valid type using a path
9931002
|${typeCode}
9941003
|"""
9951004
}

0 commit comments

Comments
 (0)