File tree 2 files changed +11
-4
lines changed
compiler/src/dotty/tools/dotc 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -136,8 +136,9 @@ object desugar {
136
136
)
137
137
138
138
/** A derived type definition watching `sym` */
139
- def derivedTypeParam (sym : TypeSymbol )(using Context ): TypeDef =
140
- TypeDef (sym.name, DerivedFromParamTree ().watching(sym)).withFlags(TypeParam )
139
+ def derivedTypeParamWithVariance (sym : TypeSymbol )(using Context ): TypeDef =
140
+ val variance = (Covariant | Contravariant ) & sym.flags
141
+ TypeDef (sym.name, DerivedFromParamTree ().watching(sym)).withFlags(TypeParam | variance)
141
142
142
143
/** A value definition copied from `vdef` with a tpt typetree derived from it */
143
144
def derivedTermParam (vdef : ValDef )(using Context ): ValDef =
@@ -406,7 +407,7 @@ object desugar {
406
407
407
408
val originalTparams = constr1.tparams
408
409
val originalVparamss = constr1.vparamss
409
- lazy val derivedEnumParams = enumClass.typeParams.map(derivedTypeParam )
410
+ lazy val derivedEnumParams = enumClass.typeParams.map(derivedTypeParamWithVariance )
410
411
val impliedTparams =
411
412
if (isEnumCase) {
412
413
val tparamReferenced = typeParamIsReferenced(
Original file line number Diff line number Diff line change @@ -166,7 +166,13 @@ class VarianceChecker(using Context) {
166
166
private object Traverser extends TreeTraverser {
167
167
def checkVariance (sym : Symbol , pos : SrcPos ) = Validator .validateDefinition(sym) match {
168
168
case Some (VarianceError (tvar, required)) =>
169
- def msg = i " ${varianceLabel(tvar.flags)} $tvar occurs in ${varianceLabel(required)} position in type ${sym.info} of $sym"
169
+ def msg =
170
+ val enumAddendum =
171
+ if sym.owner.isAllOf(EnumCase ) && sym.owner.isClass then
172
+ i " \n enum case ${sym.owner} may require explicit type parameters to resolve this issue "
173
+ else
174
+ " "
175
+ i " ${varianceLabel(tvar.flags)} $tvar occurs in ${varianceLabel(required)} position in type ${sym.info} of $sym$enumAddendum"
170
176
if (migrateTo3 &&
171
177
(sym.owner.isConstructor || sym.ownersIterator.exists(_.isAllOf(ProtectedLocal ))))
172
178
report.migrationWarning(
You can’t perform that action at this time.
0 commit comments