Skip to content

Approximate annotated types in wildApprox #22893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,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)
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/annot-default-arg-22874.scala
Original file line number Diff line number Diff line change
@@ -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
Loading