Better type inference in harmonizeUnion #2111
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.
NOTE: This PR depends on #2110 because the improved type inference revealed the bug fixed by #2110, only the last commit is new.
Before this commit, the added testcase failed because the type of
inv
was inferred to be
Inv[Any]
instead ofInv[Int]
. The situation lookslike this:
To get the type of
inv
, we callharmonizeUnion
which will take thelub of
Inv[A]
andInv[A']
, eventually this mean that we do:But since
harmonizeUnion
usesfluidly
, this does not result inA'
getting constrained to be a subtype of
A
, instead we constrainA
tothe upper bound of
A'
:We use
fluidly
to avoid creating OrTypes inlub
, but it turns outthat there is a less aggressive solution:
lub
callsmergeIfSuper
which then calls
isSubTypeWhenFrozen
, if we just make these subtypecalls non-frozen, we can achieve what we want. This is what the new
method
fluidLub
does.