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

Fix regression in instantiating type vars #16999

Closed
wants to merge 1 commit into from

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Feb 23, 2023

Fixes #16997

@dwijnand dwijnand marked this pull request as ready for review February 25, 2023 18:35
smarter added a commit to dotty-staging/dotty that referenced this pull request Feb 28, 2023
Previously, derivedSelect would incorrectly approximate `fn.R` by `? >: Nothing
<: Any` in `i16997.min.scala`, which subsequently lead to a kind-incorrect
type application `Any[Y]` that broke type inference. scala#16999 proposed to fix this
by changing type inference, but it seems like we don't need to do that if we
make sure our wildcards are always kind-correct.

Note that the wildcard logic in lookupRefined could be removed: it seems like
it was supposed to be used by `reduceProjection` according to its documentation,
but the constructor of `NamedType` disallows wildcards as prefixes so it didn't
actually do anything there.
smarter added a commit to dotty-staging/dotty that referenced this pull request Feb 28, 2023
Previously, derivedSelect would incorrectly approximate `fn.R` by `? >: Nothing
<: Any` in `i16997.min.scala`, which subsequently lead to a kind-incorrect
type application `Any[Y]` that broke type inference. scala#16999 proposed to fix this
by changing type inference, but it seems like we don't need to do that if we
make sure our wildcards are always kind-correct.

Note that the wildcard logic in lookupRefined could be removed: it seems like
it was supposed to be used by `reduceProjection` according to its documentation,
but the constructor of `NamedType` disallows wildcards as prefixes so it didn't
actually do anything there.

Co-Authored-By: Dale Wijnand <dale.wijnand@gmail.com>
@@ -4810,7 +4810,7 @@ object Types {
def hasLowerBound(using Context): Boolean = !currentEntry.loBound.isExactlyNothing

/** For uninstantiated type variables: Is the upper bound different from Any? */
def hasUpperBound(using Context): Boolean = !currentEntry.hiBound.finalResultType.isExactlyAny
def hasUpperBound(using Context): Boolean = !currentEntry.hiBound.finalResultType.isRef(defn.AnyClass) // so also `Any[..]`
Copy link
Member

Choose a reason for hiding this comment

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

This is weird: Any is not kind-polymorphic, it's not supposed to be applicable to arguments. I've opened a PR which I believe fixes the root issue: #17025

@dwijnand dwijnand closed this Mar 1, 2023
@dwijnand dwijnand deleted the fix-infer-reg branch March 1, 2023 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants