Skip to content

Commit 3c2b09f

Browse files
committed
Added explanation for CantInstatiateAbstractClassOrTrait
1 parent 40ce201 commit 3c2b09f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,18 @@ object messages {
11321132
val kind = "Usage"
11331133
private val traitOrAbstract = if (isTrait) hl"a trait" else hl"abstract"
11341134
val msg = hl"""${cls.name} is ${traitOrAbstract}; it cannot be instantiated"""
1135-
val explanation = ""
1135+
val explanation =
1136+
hl"""|Abstract classes and traits need to be extended by a concrete class or object
1137+
|to make their functionality accessible.
1138+
|
1139+
|You may want to create an anonymous class extending ${cls.name} with
1140+
| ${s"class ${cls.name} { }"}
1141+
|
1142+
|or add a companion object with
1143+
| ${s"object ${cls.name} extends ${cls.name}"}
1144+
|
1145+
|You need to implement any abstract members in both cases.
1146+
|""".stripMargin
11361147
}
11371148

11381149
}

0 commit comments

Comments
 (0)