Rework logical and/or type rules on contextual bool #1264
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.
An attempt to fix #1136 by refining the existing special case for contextual
bool
on logicalLHS && RHS
andLHS || RHS
.For a bit of background: We can't model this exactly like JS because it would involve a union
typeof(LHS) | typeof(RHS)
, so the compiler currently compiles LHS with the outer contextual type allowing it to deviate and RHS with LHS's type as the contextual type forcing an implicit conversion to get a single AOT-compatible type.The important difference this PR introduces is that the compiler no longer attempts to implicitly convert the RHS expression to the LHS type if the outer contextual type is
bool
orvoid
, instead allowing both LHS and RHS to have different types, which is fine since subsequent codegen converts each to a bool anyway.Allows us to write
but also has the (unfortunate?) side-effect that the following magically works in AS where TS would complain: