Skip to content

value of type <?> does not take parameters from wildApprox when typing a parameter with an annotated type and a default value #22874

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

Closed
mbovel opened this issue Mar 26, 2025 · 0 comments · Fixed by #22893

Comments

@mbovel
Copy link
Member

mbovel commented Mar 26, 2025

Compiler version

Scala 3.7.1-RC1-bin-20250325-701fa8a-NIGHTLY, JVM (21)

Minimized code

class annot(arg: Int) extends scala.annotation.StaticAnnotation
def foo(a: Int, b: Int @annot(a + a) = 42): Int = b

Output (click arrow to expand)

$ scala --server=false -S 3.nightly -Ydebug-error defaultArgBug.scala
-- Error: defaultArgBug.scala:2:30 ------
2 |def foo(a: Int, b: Int @annot(a + a) = 42): Int = b
  |                              ^^^^^
  |                              value of type <?> does not take parameters
java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:2210)
        at dotty.tools.dotc.report$.error(report.scala:70)
        at dotty.tools.dotc.typer.ErrorReporting$.errorType(ErrorReporting.scala:32)
        at dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:313)
        at dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:17)
        at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:154)
        at dotty.tools.dotc.ast.tpd$TypedTreeCopier.Apply(tpd.scala:680)
        at dotty.tools.dotc.ast.tpd$ConservativeTreeCopier.Apply(tpd.scala:850)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1540)
        at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:123)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1646)
        at scala.collection.immutable.List.mapConserve(List.scala:473)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1646)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1540)
        at dotty.tools.dotc.ast.TreeTypeMap.transform(TreeTypeMap.scala:123)
        at dotty.tools.dotc.ast.TreeTypeMap.apply(TreeTypeMap.scala:179)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6331)
        at dotty.tools.dotc.core.Annotations$Annotation.mapWith(Annotations.scala:71)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6241)
        at dotty.tools.dotc.typer.ProtoTypes$.dotty$tools$dotc$typer$ProtoTypes$$$wildApprox(ProtoTypes.scala:1022)
        at dotty.tools.dotc.typer.ProtoTypes$.wildApprox(ProtoTypes.scala:1025)
        at dotty.tools.dotc.typer.Namer.expectedDefaultArgType$1(Namer.scala:2193)
        at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:2217)
        at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:2243)
        at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:2244)
        at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:2255)
        at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1837)
        at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1843)
        at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1969)
        at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:843)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:1003)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:872)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:175)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:190)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:192)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:3509)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3534)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3649)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3727)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3732)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3754)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3800)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3222)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3550)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3554)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3649)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3727)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3732)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3754)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3800)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:33
@mbovel mbovel added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label area:annotations and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 26, 2025
mbovel added a commit that referenced this issue Apr 1, 2025
Fixes #22874.

`wildApprox` approximates parameter references and type variables by
wildcards. When doing so for an `AnnotatedType`, this can produce trees
with wildcards types, causing the type assigner to fail. For example,
consider `Apply(fn, args)` where `fn` has type `TermParamRef`. Applying
`wildApprox` will approximate the type of `fn` to a wildcard, leading
[the type assigner for
`Apply`](https://github.com/scala/scala3/blob/cb97c40930d335e0fca38238682d218c3e718bd8/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala#L298)
to emit an error stating that `<?>` does not take parameters.

This issue is somehow similar to the one described in
#19957 (comment),
which was fixed by #21941 (and
re-worked in #22839).

This PR fixes the issue by approximating annotated types in
`wildApprox`: annotated types are approximated by their parent types if
they are not refining, or by wildcards upper-bounded by their parent
types if they are.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant