mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +01:00
Check "x op= y".
This commit is contained in:
1 parent
3d34f6abf1
commit
33af5598cc
1 file changed
+35
-10
+35
-10
@@ -60,22 +60,47 @@ func (c *typeChecker) checkStatement(n *a.Node) error {
|
|||||||
|
|
||||||
case a.KAssign:
|
case a.KAssign:
|
||||||
o := n.Assign()
|
o := n.Assign()
|
||||||
l := o.LHS()
|
lhs := o.LHS()
|
||||||
r := o.RHS()
|
rhs := o.RHS()
|
||||||
if err := c.checkExpr(l); err != nil {
|
if err := c.checkExpr(lhs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.checkExpr(r); err != nil {
|
if err := c.checkExpr(rhs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lTyp := l.MType()
|
lTyp := lhs.MType()
|
||||||
rTyp := r.MType()
|
rTyp := rhs.MType()
|
||||||
// TODO, look at o.Operator().
|
|
||||||
if (rTyp == TypeExprIdealNumber && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) {
|
if o.Operator() == t.IDEq {
|
||||||
|
if (rTyp == TypeExprIdealNumber && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q",
|
||||||
|
rhs.String(c.idMap), rTyp.String(c.idMap), lhs.String(c.idMap), lTyp.String(c.idMap))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !lTyp.IsNumType() {
|
||||||
|
return fmt.Errorf("check: assignment %q: assignee %q, of type %q, does not have numeric type",
|
||||||
|
c.idMap.ByID(o.Operator()), lhs.String(c.idMap), lTyp.String(c.idMap))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch o.Operator() {
|
||||||
|
case t.IDShiftLEq, t.IDShiftREq:
|
||||||
|
if rTyp.IsNumType() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("check: assignment %q: shift %q, of type %q, does not have numeric type",
|
||||||
|
c.idMap.ByID(o.Operator()), rhs.String(c.idMap), rTyp.String(c.idMap))
|
||||||
|
}
|
||||||
|
|
||||||
|
if rTyp == TypeExprIdealNumber || lTyp.EqIgnoringRefinements(rTyp) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q",
|
return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types",
|
||||||
r.String(c.idMap), rTyp.String(c.idMap), l.String(c.idMap), lTyp.String(c.idMap))
|
c.idMap.ByID(o.Operator()),
|
||||||
|
lhs.String(c.idMap), rhs.String(c.idMap),
|
||||||
|
lTyp.String(c.idMap), rTyp.String(c.idMap),
|
||||||
|
)
|
||||||
|
|
||||||
case a.KVar:
|
case a.KVar:
|
||||||
o := n.Var()
|
o := n.Var()
|
||||||
|
|||||||
Reference in new issue
Block a user