Literal/constant-typed local lazy vals need refined values. #6454
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.
Compiling the following,
crashes with an unexpected type error during the Fields phase,
This is because the translation of the local lazy val in Fields maps to a
LazyIntwhich holds anIntvalue. This is too wide to assign to the1-typed val and results in a type error when the tree synthesizedduring Fields is typechecked.
I've fixed this by inserting a cast to the narrower type, which is eliminated during erasure. In principle we could switch to a scheme similar to
LazyUnitfor literal typed local lazy vals, ie. eliminating the storage for the value whilst retaining the effects, but this seems like an unlikely enough scenario to not warrant the additional complexity that this optimization would entail.This fixes scala/bug#10792.