-
Notifications
You must be signed in to change notification settings - Fork 1.8k
More type inference for more binary expressions #451
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
Conversation
Mostly just for primitive numeric types such as u32 and f64. Not yet a general solution using trait resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM apart from two nits and a missing file ;)
crates/ra_hir/src/ty.rs
Outdated
@@ -529,15 +529,40 @@ struct InferenceContext<'a, D: HirDatabase> { | |||
|
|||
// helper function that determines whether a binary operator | |||
// always returns a boolean | |||
fn is_boolean_operator(op: BinaryOp) -> bool { | |||
fn boolean_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be called binary_op_return_ty
, right? it's not just for boolean ops. Also, the comment is outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
crates/ra_hir/src/ty.rs
Outdated
let lhs_ty = self.infer_expr(*lhs, &lhs_expectation)?; | ||
// TODO: find implementation of trait corresponding to operation | ||
// symbol and resolve associated `Output` type | ||
let rhs_expectation = match op { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this big match could also be extracted into a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Will do.
} | ||
"#, | ||
"boolean_op.txt", | ||
"binary_op.txt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems you forgot to add the renamed file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhh, I forgot to add it to git I think! 😨
Thanks again for the review and apologies for the sloppy mistakes - I will try to do better! |
No problem, thank you 😄 bors r+ |
451: More type inference for more binary expressions r=flodiebold a=marcusklaas Implements more of #390. Just works for primitive (numeric) types for now. Found an issue where `let x: Ty = expr;` doesn't actually propagate the type information unless `Ty` is primitive and numeric. I'll open an issue for this. Co-authored-by: Marcus Klaas de Vries <[email protected]>
Build succeeded |
Implements more of #390. Just works for primitive (numeric) types for now.
Found an issue where
let x: Ty = expr;
doesn't actually propagate the type information unlessTy
is primitive and numeric. I'll open an issue for this.