core: improve binop and cmpop error messages #439
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Reference: M-Labs/nac3#439
Loading…
Reference in New Issue
No description provided.
Delete Branch "improve-error-432"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
NOTE: This PR depends on #437 (core: improve function call errors).
Fixes #436 (Improve type error messages for operator functions) (originally from #432 (type inferencer crash on artiq_sinara_tester)).
For #436 (Improve type error messages for operator functions), in particular, the error message is now:
For ill-typed binary operations:
For ill-typed comparison operations:
8dfd7f2a7d
to889bb20844
Force-pushed to rebase onto master since #437 has been merged.
889bb20844
to3087f77ed8
I'd prefer it to be called "invalid operand type(s)
float
andint32
for operator+
"@ -73,1 +49,3 @@
_ => None,
impl OpInfo {
#[must_use]
pub fn from_binop(op: Operator, variant: BinOpVariant) -> Self {
Why not just implement these using the
From
trait?It is possible for
Cmpop
andUnaryop
, but not forOperator
(binary operator) since it takes an extra argument, although I could create:Just implement
From<(Operator, BinOpVariant)> for OpInfo
then.Also I don't think
From
trait is meant to be used like that - it's purpose is for type conversions. Perhaps I will create atrait HasOpInfo
.@ -75,1 +77,4 @@
/// Extra details about how a [`Call`] was written by the user.
#[derive(Debug, Clone)]
pub enum CallInfo {
Call this struct
OperatorInfo
.CallInfo
was intended to be general for any kind of function call. But to be honest I cannot think of anything other than normal function calls and operator calls (includingis
andis not
and its friends). I will rename it.@ -80,6 +108,7 @@ pub struct Call {
pub ret: Type,
pub fun: RefCell<Option<Type>>,
pub loc: Option<Location>,
pub info: CallInfo,
Make this
Option<OperatorInfo>
.The current error message follows Python's:
Should we still make the change?
Use Python's error message format then.
d0ea69b7ae
toc57e0936d5
Revised
c57e0936d5
tobc9a9b28c8
bc9a9b28c8
to1e56109a52
Rebased to resolve conflicts
One nit, otherwise LGTM.
@ -62,0 +63,4 @@
/// Helper macro to conveniently build an [`OpInfo`].
///
/// Example usage: `make_info("add", "+")` generates `OpInfo { name: "__add__", symbol: "+" }`
macro_rules! make_info {
Call it
make_op_info
, since it is unclear what info you are actually producing.1e56109a52
tof52086b706
Revised by amending the commit that introduced
OpInfo