Stricter condition for type assignability #2902
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.
This adds a new
assign
function that determines whether a typeT
is assignable to an input with some definition typeD
.The old condition was "
T
andD
overlap." This condition served as well to prevent connects that could not be valid, but it's not enough anymore. The new Conditional node causes problems in that regard, because it allows users to create the union of 2 typesA
andB
. So users can e.g. create the typeImage | number
which is assignable to a number input under the old condition.To fix this issue, I modified the condition slightly. Instead of checking with
T
for overlap, it will now splitT
into its unioned types and check with those items. So the condition is now:split(T).every(item => overlap(item, D))
. The key here is howT
is split. It's a little complex, because theany
type should still be assignable to everything.split
essentially works like this:2 things to note:
any
. This is necessary, because nodes can't actually outputany
. There is special handling for theError
type, so nodes will output at mostany \ Error
.Image { width: 100 } | Image { width: 200 } | PyTorchModel
will be iterated as [Image { width: 100 } | Image { width: 200 }
,PyTorchModel
].The new assignability condition fixes the issues the Conditional node causes, but I expect that we will likely need to revise it further in the future.
Examples
Image or color:

Image or number:
