Skip to content

Commit 4421d4c

Browse files
committed
Make an exception for universal traits
They can have a value class as self type, after all.
1 parent 1c1c2f4 commit 4421d4c

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
@@ -66,6 +66,9 @@ object SymUtils:
6666

6767
def isNoValue(using Context): Boolean = self.is(Package) || self.isAllOf(JavaModule)
6868

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

0 commit comments

Comments
 (0)