File tree 5 files changed +24
-5
lines changed
compiler/src/dotty/tools/dotc
5 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -820,7 +820,7 @@ object desugar {
820
820
}
821
821
else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum)
822
822
companionDefs(anyRef, companionMembers)
823
- else if ( isValueClass)
823
+ else if isValueClass && ! isObject then
824
824
companionDefs(anyRef, Nil )
825
825
else Nil
826
826
Original file line number Diff line number Diff line change @@ -1686,10 +1686,15 @@ class CannotExtendAnyVal(sym: Symbol)(using Context)
1686
1686
extends SyntaxMsg (CannotExtendAnyValID ) {
1687
1687
def msg (using Context ) = i """ $sym cannot extend ${hl(" AnyVal" )}"""
1688
1688
def explain (using Context ) =
1689
- i """ Only classes (not traits) are allowed to extend ${hl(" AnyVal" )}, but traits may extend
1690
- | ${hl(" Any" )} to become ${Green (" \" universal traits\" " )} which may only have ${hl(" def" )} members.
1691
- |Universal traits can be mixed into classes that extend ${hl(" AnyVal" )}.
1692
- | """
1689
+ if sym.is(Trait ) then
1690
+ i """ Only classes (not traits) are allowed to extend ${hl(" AnyVal" )}, but traits may extend
1691
+ | ${hl(" Any" )} to become ${Green (" \" universal traits\" " )} which may only have ${hl(" def" )} members.
1692
+ |Universal traits can be mixed into classes that extend ${hl(" AnyVal" )}.
1693
+ | """
1694
+ else if sym.is(Module ) then
1695
+ i """ Only classes (not objects) are allowed to extend ${hl(" AnyVal" )}.
1696
+ | """
1697
+ else " "
1693
1698
}
1694
1699
1695
1700
class CannotExtendJavaEnum (sym : Symbol )(using Context )
Original file line number Diff line number Diff line change @@ -711,6 +711,8 @@ object Checking {
711
711
if (isDerivedValueClass(clazz)) {
712
712
if (clazz.is(Trait ))
713
713
report.error(CannotExtendAnyVal (clazz), clazz.srcPos)
714
+ if clazz.is(Module ) then
715
+ report.error(CannotExtendAnyVal (clazz), clazz.srcPos)
714
716
if (clazz.is(Abstract ))
715
717
report.error(ValueClassesMayNotBeAbstract (clazz), clazz.srcPos)
716
718
if (! clazz.isStatic)
Original file line number Diff line number Diff line change
1
+ -- [E068] Syntax Error: tests/neg/i18274.scala:3:7 ---------------------------------------------------------------------
2
+ 3 |object Foo extends AnyVal // error
3
+ | ^
4
+ | object Foo cannot extend AnyVal
5
+ |---------------------------------------------------------------------------------------------------------------------
6
+ | Explanation (enabled by `-explain`)
7
+ |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8
+ | Only classes (not objects) are allowed to extend AnyVal.
9
+ ---------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
1
+ //> using options -explain
2
+
3
+ object Foo extends AnyVal // error
You can’t perform that action at this time.
0 commit comments