Skip to content

Commit efd39cc

Browse files
committed
Soften anomaly when mapping annotations
A TypeMap mapped annotations only if the underlying types were different. There's no fundamental reason why this should be so. We now map concrete annotations also if they contain a subtree that gets a different type under the mapping.
1 parent d8cf8a3 commit efd39cc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ object TypeOps:
162162
// with Nulls (which have no base classes). Under -Yexplicit-nulls, we take
163163
// corrective steps, so no widening is wanted.
164164
simplify(l, theMap) | simplify(r, theMap)
165-
case AnnotatedType(parent, annot)
166-
if annot.symbol == defn.UncheckedVarianceAnnot && !ctx.mode.is(Mode.Type) && !theMap.isInstanceOf[SimplifyKeepUnchecked] =>
167-
simplify(parent, theMap)
165+
case tp @ AnnotatedType(parent, annot) =>
166+
val parent1 = simplify(parent, theMap)
167+
if annot.symbol == defn.UncheckedVarianceAnnot
168+
&& !ctx.mode.is(Mode.Type)
169+
&& !theMap.isInstanceOf[SimplifyKeepUnchecked]
170+
then parent1
171+
else tp.derivedAnnotatedType(parent1, annot)
168172
case _: MatchType =>
169173
val normed = tp.tryNormalize
170174
if (normed.exists) normed else mapOver

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5423,8 +5423,17 @@ object Types {
54235423

54245424
case tp @ AnnotatedType(underlying, annot) =>
54255425
val underlying1 = this(underlying)
5426-
if (underlying1 eq underlying) tp
5427-
else derivedAnnotatedType(tp, underlying1, mapOver(annot))
5426+
val annot1 =
5427+
if underlying1 ne underlying then mapOver(annot)
5428+
else annot match
5429+
case ConcreteAnnotation(ann)
5430+
if ann.existsSubTree { t =>
5431+
val tpe = t.typeOpt
5432+
tpe.exists && !(this(tpe) =:= tpe)
5433+
} => mapOver(annot)
5434+
case _ => annot
5435+
if (underlying1 eq underlying) && (annot eq annot1) then tp
5436+
else derivedAnnotatedType(tp, underlying1, annot1)
54285437

54295438
case _: ThisType
54305439
| _: BoundType

0 commit comments

Comments
 (0)