Skip to content

Commit 64f691d

Browse files
authored
Merge pull request #342 from scala/backport-lts-3.3-22893
Backport "Approximate annotated types in `wildApprox`" to 3.3 LTS
2 parents aed0a27 + 7c90bb2 commit 64f691d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,15 @@ object ProtoTypes {
950950
paramInfos = tl.paramInfos.mapConserve(wildApprox(_, theMap, seen, internal1).bounds),
951951
resType = wildApprox(tl.resType, theMap, seen, internal1)
952952
)
953+
case tp @ AnnotatedType(parent, _) =>
954+
// This case avoids approximating types in the annotation tree, which can
955+
// cause the type assigner to fail.
956+
// See #22893 and tests/pos/annot-default-arg-22874.scala.
957+
val parentApprox = wildApprox(parent, theMap, seen, internal)
958+
if tp.isRefining then
959+
WildcardType(TypeBounds.upper(parentApprox))
960+
else
961+
parentApprox
953962
case _ =>
954963
(if (theMap != null && seen.eq(theMap.seen)) theMap else new WildApproxMap(seen, internal))
955964
.mapOver(tp)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package defaultArgBug
2+
3+
class staticAnnot(arg: Int) extends scala.annotation.StaticAnnotation
4+
class refiningAnnot(arg: Int) extends scala.annotation.RefiningAnnotation
5+
6+
def f1(a: Int, b: Int @staticAnnot(a + a) = 42): Int = b
7+
def f2(a: Int, b: Int @refiningAnnot(a + a) = 42): Int = b

0 commit comments

Comments
 (0)