@@ -811,11 +811,16 @@ object RefChecks {
811
811
* can assume invariant refinement for case classes in `constrainPatternType`.
812
812
*/
813
813
def checkCaseClassInheritanceInvariant () =
814
- for (caseCls <- clazz.info.baseClasses.tail.find(_.is(Case )))
815
- for (baseCls <- caseCls.info.baseClasses.tail)
816
- if (baseCls.typeParams.exists(_.paramVarianceSign != 0 ))
817
- for (problem <- variantInheritanceProblems(baseCls, caseCls, " non-variant" , " case " ))
818
- report.errorOrMigrationWarning(problem, clazz.srcPos, from = `3.0`)
814
+ for
815
+ caseCls <- clazz.info.baseClasses.tail.find(_.is(Case ))
816
+ baseCls <- caseCls.info.baseClasses.tail
817
+ if baseCls.typeParams.exists(_.paramVarianceSign != 0 )
818
+ problem <- variantInheritanceProblems(baseCls, caseCls, i " base $baseCls" , " case " )
819
+ withExplain = problem.appendExplanation:
820
+ """ Refining a basetype of a case class is not allowed.
821
+ |This is a limitation that enables better GADT constraints in case class patterns""" .stripMargin
822
+ do report.errorOrMigrationWarning(withExplain, clazz.srcPos, from = `3.0`)
823
+
819
824
checkNoAbstractMembers()
820
825
if (abstractErrors.isEmpty)
821
826
checkNoAbstractDecls(clazz)
@@ -844,7 +849,7 @@ object RefChecks {
844
849
for {
845
850
cls <- clazz.info.baseClasses.tail
846
851
if cls.paramAccessors.nonEmpty && ! mixins.contains(cls)
847
- problem <- variantInheritanceProblems(cls, clazz.asClass.superClass, " parameterized" , " super" )
852
+ problem <- variantInheritanceProblems(cls, clazz.asClass.superClass, i " parameterized base $cls " , " super" )
848
853
}
849
854
report.error(problem, clazz.srcPos)
850
855
}
@@ -867,7 +872,7 @@ object RefChecks {
867
872
if (combinedBT =:= thisBT) None // ok
868
873
else
869
874
Some (
870
- em """ illegal inheritance: $clazz inherits conflicting instances of $baseStr base $baseCls .
875
+ em """ illegal inheritance: $clazz inherits conflicting instances of $baseStr.
871
876
|
872
877
| Direct basetype: $thisBT
873
878
| Basetype via $middleStr$middle: $combinedBT""" )
@@ -966,9 +971,9 @@ object RefChecks {
966
971
end checkNoPrivateOverrides
967
972
968
973
def checkVolatile (sym : Symbol )(using Context ): Unit =
969
- if sym.isVolatile && ! sym.is(Mutable ) then
974
+ if sym.isVolatile && ! sym.is(Mutable ) then
970
975
report.warning(VolatileOnVal (), sym.srcPos)
971
-
976
+
972
977
/** Check that unary method definition do not receive parameters.
973
978
* They can only receive inferred parameters such as type parameters and implicit parameters.
974
979
*/
0 commit comments