Skip to content

Fix #7149: Revert inference change #7161

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 3 commits into from
Sep 3, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 3, 2019

With #7114, we had a new failure scenario: A pair of <indent> ... <outdent> created a block where none was before which caused an additional interpolation step in Typer. The interpolation would instantiate type variables that occurred only co- or contra-variantly in the result type. This caused a problem for inferring type arguments for asInstanceOf. An example is in type-propagation.scala:

def foo: String =
    "abc".asInstanceOf

Significant indentation expanded this fragment as if it was

def foo: String = {
    "abc".asInstanceOf
}

The interpolation then inferred the result type of asInstanceOf to be Nothing, even though a result type String was known.

The original fix in #7130 was to not interpolate to Nothing in this case. Unfortunately, that broke type inference. #7149 is one example, the example in fastparse another.

One could argue that asInstanceOf should always get explicit type arguments, since inference from result type is very fragile. But the fact is there's a lot of code that uses asInstanceOf in the way shown above.

What this PR does instead is not to create a Block around a single indented expression. So, we generate the same trees as before.

Undo the change where we do not interpolate a type variable if
its lower bound is nothing. It turned out this broke type inference.
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

@odersky odersky merged commit 85962b1 into scala:master Sep 3, 2019
@odersky odersky deleted the fix-#7149 branch September 3, 2019 17:04
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