Skip to content

Commit 8f9d33c

Browse files
committed
Make an exception for universal traits
They can have a value class as self type, after all.
1 parent 24f5055 commit 8f9d33c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package transform
33

44
import core._
55
import Contexts._, Types._, MegaPhase._, ast.Trees._, Symbols._, Decorators._, Flags._
6+
import SymUtils.*
67

78
/** Transform references of the form
89
*
@@ -30,7 +31,7 @@ class ExplicitSelf extends MiniPhase {
3031

3132
private def castQualifier(tree: RefTree, cls: ClassSymbol, thiz: Tree)(using Context) =
3233
val selfType = cls.classInfo.selfType
33-
if selfType.classSymbols.exists(_.isValueClass) then
34+
if selfType.classSymbols.exists(_.isValueClass) && !cls.isUniversalTrait then
3435
report.error(em"self type $selfType of $cls may not be a value class", thiz.srcPos)
3536
cpy.Select(tree)(thiz.cast(AndType(selfType, thiz.tpe)), tree.name)
3637

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ object SymUtils:
6464

6565
def isSuperAccessor(using Context): Boolean = self.name.is(SuperAccessorName)
6666

67+
def isUniversalTrait(using Context): Boolean =
68+
self.is(Trait) && self.asClass.parentSyms.head == defn.AnyClass
69+
6770
/** Is this a type or term parameter or a term parameter accessor? */
6871
def isParamOrAccessor(using Context): Boolean =
6972
self.is(Param) || self.is(ParamAccessor)

0 commit comments

Comments
 (0)