Skip to content

Commit 950bd90

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 73f8482 commit 950bd90

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
@@ -163,9 +163,13 @@ object TypeOps:
163163
// with Nulls (which have no base classes). Under -Yexplicit-nulls, we take
164164
// corrective steps, so no widening is wanted.
165165
simplify(l, theMap) | simplify(r, theMap)
166-
case AnnotatedType(parent, annot)
167-
if annot.symbol == defn.UncheckedVarianceAnnot && !ctx.mode.is(Mode.Type) && !theMap.isInstanceOf[SimplifyKeepUnchecked] =>
168-
simplify(parent, theMap)
166+
case tp @ AnnotatedType(parent, annot) =>
167+
val parent1 = simplify(parent, theMap)
168+
if annot.symbol == defn.UncheckedVarianceAnnot
169+
&& !ctx.mode.is(Mode.Type)
170+
&& !theMap.isInstanceOf[SimplifyKeepUnchecked]
171+
then parent1
172+
else tp.derivedAnnotatedType(parent1, annot)
169173
case _: MatchType =>
170174
val normed = tp.tryNormalize
171175
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
@@ -5566,8 +5566,17 @@ object Types {
55665566

55675567
case tp @ AnnotatedType(underlying, annot) =>
55685568
val underlying1 = this(underlying)
5569-
if (underlying1 eq underlying) tp
5570-
else derivedAnnotatedType(tp, underlying1, mapOver(annot))
5569+
val annot1 =
5570+
if underlying1 ne underlying then mapOver(annot)
5571+
else annot match
5572+
case ConcreteAnnotation(ann)
5573+
if ann.existsSubTree { t =>
5574+
val tpe = t.typeOpt
5575+
tpe.exists && !(this(tpe) =:= tpe)
5576+
} => mapOver(annot)
5577+
case _ => annot
5578+
if (underlying1 eq underlying) && (annot eq annot1) then tp
5579+
else derivedAnnotatedType(tp, underlying1, annot1)
55715580

55725581
case tp @ CapturingType(parent, refs) =>
55735582
derivedCapturingType(tp, this(parent), refs.flatMap(this(_).captureSet))

0 commit comments

Comments
 (0)