From 7c90bb25fea12f6869eb7f2b3bae75c10fd0ac5e Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 31 Mar 2025 19:50:37 +0000 Subject: [PATCH] Approximate annotated types in `wildApprox` [Cherry-picked 4cdeb81184d74a9b3c2d6d728c054e87b842898c] --- compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala | 9 +++++++++ tests/pos/annot-default-arg-22874.scala | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/pos/annot-default-arg-22874.scala diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 89a2cbbfbc21..db2faa2b28fd 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -950,6 +950,15 @@ object ProtoTypes { paramInfos = tl.paramInfos.mapConserve(wildApprox(_, theMap, seen, internal1).bounds), resType = wildApprox(tl.resType, theMap, seen, internal1) ) + case tp @ AnnotatedType(parent, _) => + // This case avoids approximating types in the annotation tree, which can + // cause the type assigner to fail. + // See #22893 and tests/pos/annot-default-arg-22874.scala. + val parentApprox = wildApprox(parent, theMap, seen, internal) + if tp.isRefining then + WildcardType(TypeBounds.upper(parentApprox)) + else + parentApprox case _ => (if (theMap != null && seen.eq(theMap.seen)) theMap else new WildApproxMap(seen, internal)) .mapOver(tp) diff --git a/tests/pos/annot-default-arg-22874.scala b/tests/pos/annot-default-arg-22874.scala new file mode 100644 index 000000000000..7a983f4d3351 --- /dev/null +++ b/tests/pos/annot-default-arg-22874.scala @@ -0,0 +1,7 @@ +package defaultArgBug + +class staticAnnot(arg: Int) extends scala.annotation.StaticAnnotation +class refiningAnnot(arg: Int) extends scala.annotation.RefiningAnnotation + +def f1(a: Int, b: Int @staticAnnot(a + a) = 42): Int = b +def f2(a: Int, b: Int @refiningAnnot(a + a) = 42): Int = b