Drop the "= RHS" out of "var x T = RHS"

This commit is contained in:
Nigel Tao committed 2018-12-27 11:29:47 +11:00
1 parent cbe19f50e0
commit 6dc68950c0
7 files changed
+20 -68

No files matched your search

+4 -7
View File
@@ -699,13 +699,10 @@ func (q *checker) bcheckVar(n *a.Var) error {
lhs := a.NewExpr(0, 0, 0, n.Name(), nil, nil, nil, nil)
lhs.SetMType(n.XType())
rhs := n.Value()
if rhs == nil {
// "var x T" has an implicit "= 0".
//
// TODO: check that T is an integer type.
rhs = zeroExpr
}
// "var x T" has an implicit "= 0".
//
// TODO: check that T is an integer type.
rhs := zeroExpr
return q.bcheckAssignment(lhs, t.IDEq, rhs)
}
+1 -13
View File
@@ -193,19 +193,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if n.XType().AsNode().MType() == nil {
return fmt.Errorf("check: internal error: unchecked type expression %q", n.XType().Str(q.tm))
}
if value := n.Value(); value != nil {
if err := q.tcheckExpr(value, 0); err != nil {
return err
}
lTyp := n.XType()
rTyp := value.MType()
if err := q.tcheckEq(n.Name(), nil, lTyp, value, rTyp); err != nil {
return err
}
} else {
// TODO: check that the default zero value is assignable to n.XType().
}
// TODO: check that the default zero value is assignable to n.XType().
case a.KWhile:
n := n.AsWhile()