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

Fix type inference problem on generics #609

Merged
merged 3 commits into from
Jul 20, 2022
Merged

Conversation

soutaro
Copy link
Owner

@soutaro soutaro commented Jul 20, 2022

Fixes #595

@@ -2731,6 +2731,10 @@ def type_lambda(node, params_node:, body_node:, type_hint:)
)

if expected_block_type = block_constr.block_context.body_type
type_vars = expected_block_type.free_variables
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is the fix.

The type error is caused by type checking lambda return type with given hint, which was type variable.
The type variable in the hint doesn't make any sense, because the lambda will be type checked with the hint in next step. The change apply a substitution that replaces all type variables to untyped.

@soutaro soutaro enabled auto-merge July 20, 2022 01:15
@soutaro soutaro merged commit f890f87 into master Jul 20, 2022
@soutaro soutaro deleted the generic-type-inference-bug branch July 20, 2022 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference for generic-type method is wrong when nil is part of the type
1 participant