@@ -760,9 +760,14 @@ object Checking {
760
760
// enum extending a value class type (AnyVal or an alias of it)
761
761
// The error message 'EnumMayNotBeValueClassesID' will take care of generating the error message (See #22236)
762
762
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
+ }
766
771
767
772
if (clazz.is(Trait ))
768
773
report.error(CannotExtendAnyVal (clazz), clazz.srcPos)
@@ -775,7 +780,7 @@ object Checking {
775
780
if (! clazz.isStatic)
776
781
report.error(ValueClassesMayNotBeContainted (clazz), clazz.srcPos)
777
782
if (isExtendingAliasOfAnyVal)
778
- report.error(ValueClassCannotExtendAliasOfAnyVal (clazz, parent .symbol), clazz.srcPos)
783
+ report.error(ValueClassCannotExtendAliasOfAnyVal (clazz, parentOpt.get .symbol), clazz.srcPos)
779
784
if (isDerivedValueClass(underlyingOfValueClass(clazz.asClass).classSymbol))
780
785
report.error(ValueClassesMayNotWrapAnotherValueClass (clazz), clazz.srcPos)
781
786
else {
0 commit comments