[ty] Avoid dictionary key narrowing for multi-target assignments#23523
[ty] Avoid dictionary key narrowing for multi-target assignments#23523ibraheemdev merged 1 commit intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
|
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
40 | 0 | 0 |
invalid-assignment |
4 | 0 | 0 |
unresolved-attribute |
2 | 2 | 0 |
unsupported-operator |
0 | 4 | 0 |
invalid-argument-type |
1 | 2 | 0 |
invalid-return-type |
1 | 0 | 0 |
| Total | 48 | 8 | 0 |
sharkdp
left a comment
There was a problem hiding this comment.
However, it looks like we do have internal support for associating multiple definitions with a single AST node, but we currently panic if it ever happens. I'm not sure if the assert is just enforcing our current behavior, or there's some other reason we avoid this?
I can't answer this question, but this looks like a good (intermediate) solution to avoid the panic. Thanks.
Currently I think the only place where we associate multiple definitions with a single AST node is |
|
Going to merge the easy fix for now at least. |
Originally we didn't allow this. Then we added support for it because it was necessary for So if you want to have a new node kind support multiple definitions, it just means you have to ensure that wherever type-inference accesses definitions for that node kind, it does not use |
The example below currently panics.
We attempt to synthesize places for
x["a"]andy["a"]and associate them with a definition for the key-value assignment. However, the definition is uniquely identified by the AST node for"a", causing a panic.This PR avoids narrowing for multi-target assignments. However, it looks like we do have internal support for associating multiple definitions with a single AST node, but we currently panic if it ever happens. I'm not sure if the assert is just enforcing our current behavior, or there's some other reason we avoid this?
Resolves astral-sh/ty#2866.