improve collection type inference#16530
Merged
132ikl merged 1 commit intonushell:mainfrom Sep 24, 2025
Merged
Conversation
Member
|
awesome!! i'll take a look when i get a chance |
Bahex
approved these changes
Sep 21, 2025
Member
Bahex
left a comment
There was a problem hiding this comment.
I think putting this logic into a method like Type::widen(self, other: Self) -> Self would be a little neater.
Other than that I have no complaints 👍
# Description
Fixes order-dependent table type inference bugs and introduces similar
type widening for lists:
```nushell
def get_type [] { scope variables | where name == "$foo" | first | get type }
let foo = [ [bar]; [ { baz: 1 } ], [ { baz: 1, extra: true } ] ]
get_type # table<bar: record<baz: int, extra: bool>> -> table<bar: record<baz: int>>
let foo = [ [bar]; [ { baz: 1, extra: true } ], [ { baz: 1 } ] ]
get_type # table<bar: any> -> table<bar: record<baz: int>>
let foo = [ { baz: 1 }, { baz: 1, extra: true } ]
get_type # list<any> -> list<record<baz: int>>
```
9c5b968 to
7056566
Compare
132ikl
reviewed
Sep 24, 2025
| } else if other.is_subtype_of(&self) { | ||
| self | ||
| } else { | ||
| Type::Any |
Member
There was a problem hiding this comment.
would be a good spot to improve in the future. for example, if self and other are lists of different types then we can widen to list<any>. it looks like you are handling this for list expressions already but it would be good to generalize it as well
Member
|
thanks! sorry it took so long on this one, i forgot about it 😢 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #16421
Release notes summary - What our users need to know
Fixes order-dependent table type inference bugs and introduces similar type widening for lists: