Skip to content

Commit c564511

Browse files
Merge pull request #2485 from ennru/ennru_CannotExtendAnyVal
Explanation for 'traits cannot extend AnyVal'
2 parents d8955ce + 502e7e7 commit c564511

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,11 @@ object messages {
14701470
extends Message(CannotExtendAnyValID) {
14711471
val msg = hl"""$sym cannot extend ${"AnyVal"}"""
14721472
val kind = "Syntax"
1473-
val explanation = ""
1473+
val explanation =
1474+
hl"""Only classes (not traits) are allowed to extend ${"AnyVal"}, but traits may extend
1475+
|${"Any"} to become ${Green("\"universal traits\"")} which may only have ${"def"} members.
1476+
|Universal traits can be mixed into classes that extend ${"AnyVal"}.
1477+
|"""
14741478
}
14751479

14761480
case class CannotHaveSameNameAs(sym: Symbol, cls: Symbol)(implicit ctx: Context)

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ object Checking {
449449
}
450450
if (isDerivedValueClass(clazz)) {
451451
if (clazz.is(Trait))
452-
ctx.error("Only classes (not traits) are allowed to extend AnyVal", clazz.pos)
452+
ctx.error(CannotExtendAnyVal(clazz), clazz.pos)
453453
if (clazz.is(Abstract))
454454
ctx.error("`abstract' modifier cannot be used with value classes", clazz.pos)
455455
if (!clazz.isStatic)

0 commit comments

Comments
 (0)