@@ -5392,6 +5392,17 @@ object Types {
5392
5392
variance = saved
5393
5393
derivedLambdaType(tp)(ptypes1, this (restpe))
5394
5394
5395
+ protected def isRange (tp : Type ): Boolean = tp.isInstanceOf [Range ]
5396
+
5397
+ private def diffType (ann : Tree ): Type =
5398
+ val acc = new TreeAccumulator [Type ]:
5399
+ def apply (x : Type , tree : Tree )(using Context ): Type =
5400
+ if isRange(x) then x
5401
+ else
5402
+ val tp1 = thisMap(tree.tpe)
5403
+ foldOver(if tp1 =:= tree.tpe then x else tp1, tree)
5404
+ acc(NoType , ann)
5405
+
5395
5406
/** Map this function over given type */
5396
5407
def mapOver (tp : Type ): Type = {
5397
5408
record(s " TypeMap mapOver ${getClass}" )
@@ -5435,17 +5446,16 @@ object Types {
5435
5446
5436
5447
case tp @ AnnotatedType (underlying, annot) =>
5437
5448
val underlying1 = this (underlying)
5438
- val annot1 =
5439
- if underlying1 ne underlying then mapOver(annot)
5440
- else annot match
5441
- case ConcreteAnnotation (ann)
5442
- if ann.existsSubTree { t =>
5443
- val tpe = t.typeOpt
5444
- tpe.exists && ! (this (tpe) =:= tpe)
5445
- } => mapOver(annot)
5446
- case _ => annot
5447
- if (underlying1 eq underlying) && (annot eq annot1) then tp
5448
- else derivedAnnotatedType(tp, underlying1, annot1)
5449
+ if (underlying1 ne underlying) || annot.isInstanceOf [ConcreteAnnotation ] then
5450
+ val diff = diffType(annot.tree)
5451
+ if isRange(diff) then
5452
+ // Can't map a tree type to a Range, drop annotation instead
5453
+ underlying1
5454
+ else
5455
+ val annot1 = if diff.exists then mapOver(annot) else annot
5456
+ derivedAnnotatedType(tp, underlying1, annot1)
5457
+ else
5458
+ derivedAnnotatedType(tp, underlying1, annot)
5449
5459
5450
5460
case _ : ThisType
5451
5461
| _ : BoundType
@@ -5566,8 +5576,6 @@ object Types {
5566
5576
5567
5577
protected def emptyRange = range(defn.NothingType , defn.AnyType )
5568
5578
5569
- protected def isRange (tp : Type ): Boolean = tp.isInstanceOf [Range ]
5570
-
5571
5579
protected def lower (tp : Type ): Type = tp match {
5572
5580
case tp : Range => tp.lo
5573
5581
case _ => tp
0 commit comments