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.
Subtyping between union types can be improved by skipping common types. This happens on
#filter_map
.Assume the following type definition:
and a Ruby code
We want the type of the expression to be
Array[String]
, but it returnsArray[String | nil]
. A subtyping check happens withString | nil <: T | nil | false
, and was solved toT == String | nil
.The hack is to try types without type variables before types with type variables.
nil <: T | nil | false
triesnil <: nil
andnil <: false
beforenil <: T
.nil <: nil
holds, and the laternil <: T
isn't tried.And we have
Array[String]
! 🎉