-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
…`TypeMap`s" This reverts commit bb63e31.
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.
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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 = ...
No description provided.