From cb97c40930d335e0fca38238682d218c3e718bd8 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` --- compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala | 6 ++++++ tests/pos/annot-default-arg-22839.scala | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/pos/annot-default-arg-22839.scala diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 0cc4aaabfc93..278352ed62f4 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -1017,6 +1017,12 @@ object ProtoTypes { paramInfos = tl.paramInfos.mapConserve(wildApprox(_, theMap, seen, internal1).bounds), resType = wildApprox(tl.resType, theMap, seen, internal1) ) + case tp @ AnnotatedType(parent, _) => + 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-22839.scala b/tests/pos/annot-default-arg-22839.scala new file mode 100644 index 000000000000..7a983f4d3351 --- /dev/null +++ b/tests/pos/annot-default-arg-22839.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