Fix #7149: Revert inference change #7161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 forasInstanceOf. An example is intype-propagation.scala:Significant indentation expanded this fragment as if it was
The interpolation then inferred the result type of
asInstanceOfto beNothing, even though a result typeStringwas known.The original fix in #7130 was to not interpolate to
Nothingin this case. Unfortunately, that broke type inference. #7149 is one example, the example infastparseanother.One could argue that
asInstanceOfshould always get explicit type arguments, since inference from result type is very fragile. But the fact is there's a lot of code that usesasInstanceOfin the way shown above.What this PR does instead is not to create a
Blockaround a single indented expression. So, we generate the same trees as before.