Skip to content

Commit 88e8387

Browse files
committed
address reviews
1 parent 27a7485 commit 88e8387

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,14 @@ object Checking {
760760
// enum extending a value class type (AnyVal or an alias of it)
761761
// The error message 'EnumMayNotBeValueClassesID' will take care of generating the error message (See #22236)
762762
if (clazz.isDerivedValueClass && !clazz.isEnumAnonymClass) {
763-
val implTree @ Template(_, _, _, _) = cdef.rhs: @unchecked
764-
val parent = implTree.parents.head
765-
val isExtendingAliasOfAnyVal = parent.tpe.nn.dealias =:= defn.AnyValType && parent.symbol.isAliasType
763+
val parentOpt = cdef.rhs match {
764+
case impl: Template =>
765+
impl.parents.headOption
766+
case _ => None
767+
}
768+
val isExtendingAliasOfAnyVal = parentOpt.exists { parent =>
769+
parent.symbol.isAliasType && parent.tpe.nn.dealias =:= defn.AnyValType
770+
}
766771

767772
if (clazz.is(Trait))
768773
report.error(CannotExtendAnyVal(clazz), clazz.srcPos)
@@ -775,7 +780,7 @@ object Checking {
775780
if (!clazz.isStatic)
776781
report.error(ValueClassesMayNotBeContainted(clazz), clazz.srcPos)
777782
if (isExtendingAliasOfAnyVal)
778-
report.error(ValueClassCannotExtendAliasOfAnyVal(clazz, parent.symbol), clazz.srcPos)
783+
report.error(ValueClassCannotExtendAliasOfAnyVal(clazz, parentOpt.get.symbol), clazz.srcPos)
779784
if (isDerivedValueClass(underlyingOfValueClass(clazz.asClass).classSymbol))
780785
report.error(ValueClassesMayNotWrapAnotherValueClass(clazz), clazz.srcPos)
781786
else {

0 commit comments

Comments
 (0)