Skip to content
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

Avoid loosing denotations of named types during integrate #22839

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Mar 19, 2025

No description provided.

@mbovel mbovel requested a review from odersky March 20, 2025 14:51
mbovel added a commit that referenced this pull request 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.
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

private class IntegrateMap(params: List[Symbol], paramRefs: List[Type])(using Context) extends TypeMap:
override def apply(tp: Type) =
tp match
case tp: NamedType if params.contains(tp.symbol) => paramRefs(params.indexOf(tp.symbol))
Copy link
Contributor

@odersky odersky Apr 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicates code from SubstMap, but at lower performance. I think we should factor out only what is essential here:

  • Make Substituters.SubstMap non-final and note that it is overridden by IntergrateMap in the comment.

  • Define IntegrateMap as

    private class IntegrateMap(params: List[Symbol], paramRefs: 
      List[Type])(using Context) extends Substituters.SubstMap(params, paramrefs):
      override def derivedSelect(tp: NamedType, pre: Type): Type = ...

@odersky odersky assigned mbovel and unassigned odersky Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants