Skip to content

Commit 026699a

Browse files
committed
Give context for code examples to ease understanding
1 parent 79ac5a8 commit 026699a

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
@@ -972,25 +972,34 @@ object messages {
972972
val kind = "Syntax"
973973
val msg = hl"""Expected an additional member selection after the keyword ${"this"}"""
974974

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

980988
val typeCode =
981-
"""type T = MyClass.this.Member
982-
|// ^^^^^^^
983-
"""
989+
""" type T = Outer.this.Member
990+
| // ^^^^^^^"""
984991

985992
val explanation =
986993
hl"""|Paths of imports and type selections must not end with the keyword ${"this"}.
987994
|
988-
|Maybe you forgot to select a member of ${"this"}?
995+
|Maybe you forgot to select a member of ${"this"}? As an example, in the
996+
|following context:
997+
|${contextCode}
989998
|
990-
|- Example for a valid import expression using a path
999+
|- this is a valid import expression using a path
9911000
|${importCode}
9921001
|
993-
|- Example for a valid type using a path
1002+
|- this is a valid type using a path
9941003
|${typeCode}
9951004
|"""
9961005
}

0 commit comments

Comments
 (0)