Add diagnostic for integer division by zero#13576
Conversation
While working on #13576 I noticed that it was really hard to tell which assertion failed in some of these test cases. This could be expanded to elsewhere, but I've heard this test suite format won't be around for long?
|
| &[ | ||
| "Cannot divide type 'Literal[1]' by zero.", | ||
| "Cannot divide type 'Literal[2]' by zero.", | ||
| "Cannot divide type 'Literal[3]' by zero.", |
There was a problem hiding this comment.
We could want a special message for modulo.
There was a problem hiding this comment.
Modulo requires division to calculate, so I think the error message is accurate and adequate as is.
There was a problem hiding this comment.
Agree, but not all beginners may realize that! Seems fine unless we receive significant feedback though.
There was a problem hiding this comment.
Yeah I agree with @zanieb here -- the current message is entirely accurate, but I think even your average Python user (letalone a beginner) doesn't necessarily think about modulo operations in terms of their desugared sub-operations, so I think encountering this error message here might be pretty surprising to a lot of our users. It's definitely not the biggest issue in the world, but I think a better error message here would be really worthwhile (and I actually think it's probably better to do it now before we forget about it)
I think it should be something like a match pattern for |
8b8a901 to
d7c95fa
Compare
|
I made some relatively significant changes per the review. Thanks again Carl. |
| .unwrap_or(Type::Todo), | ||
| .unwrap_or_else(|| builtins_symbol_ty(self.db, "int").to_instance(self.db)), |
There was a problem hiding this comment.
Per discussion, division by zero (and overflows, which should never occur here) don't matter when determining the inferred type.
| &[ | ||
| "Cannot divide type 'Literal[1]' by zero.", | ||
| "Cannot divide type 'Literal[2]' by zero.", | ||
| "Cannot divide type 'Literal[3]' by zero.", |
There was a problem hiding this comment.
Modulo requires division to calculate, so I think the error message is accurate and adequate as is.
d7c95fa to
d16c5d4
Compare
Adds a diagnostic for division by the integer zero in
//,/, and%.Doesn't handle
<int> / 0.0because we don't track the values of float literals.