Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Fix .to_instance() for union types #13319

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Sep 10, 2024

No description provided.

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Sep 10, 2024
Copy link
Contributor

github-actions bot commented Sep 10, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Comment on lines 457 to 458
// TODO: converting to `Unknown` here is probably correct,
// but should result in a diagnostic reporting the use of an unbound name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diagnostic should be handled by just visiting all Name exprs with Load context and checking if their type is unbound, it shouldn't be handled in every method of Type where we see an Unbound. So I'm not sure we need a TODO for it here.

(TBH I'm getting more and more convinced that Unbound should not be a Type variant at all.)

Type::Class(class) => Type::Instance(*class),
_ => Type::Unknown, // TODO type errors
Type::Union(union) => union.map(db, |element| element.to_instance(db)),
// TODO: we can probably do better here: --Alex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - it should just be a map over the elements resulting in a new intersection, as far as positive elements of the intersection go. But negative elements make it a bit tricky. I think maybe they would just get discarded, but I need to think about it more. Doesn't need to be handled in this PR, anyway.

@AlexWaygood AlexWaygood enabled auto-merge (squash) September 10, 2024 22:37
@AlexWaygood AlexWaygood merged commit a7b8cc0 into main Sep 10, 2024
17 checks passed
@AlexWaygood AlexWaygood deleted the alex/redknot-to-instance branch September 10, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants