py/compile: Simplify syntax-error messages for illegal assignments.
With this patch all illegal assignments are reported as "can't assign to
expression". Before the patch there were special cases for a literal on
the LHS, and for augmented assignments (eg +=), but it seems a waste of
bytes (and there are lots of bytes used in error messages) to spend on
distinguishing such errors which a user will rarely encounter.
diff --git a/py/compile.c b/py/compile.c
index 1e49a35..1f9eb84 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -456,8 +456,7 @@
break;
}
} else {
- compile_syntax_error(comp, pn, "can't assign to literal");
- return;
+ goto cannot_assign;
}
} else {
// pn must be a struct
@@ -472,7 +471,7 @@
case PN_exprlist:
// lhs is a tuple
if (assign_kind != ASSIGN_STORE) {
- goto bad_aug;
+ goto cannot_assign;
}
c_assign_tuple(comp, MP_PARSE_NODE_NULL, MP_PARSE_NODE_STRUCT_NUM_NODES(pns), pns->nodes);
break;
@@ -485,7 +484,7 @@
} else {
assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_testlist_comp));
if (assign_kind != ASSIGN_STORE) {
- goto bad_aug;
+ goto cannot_assign;
}
pns = (mp_parse_node_struct_t*)pns->nodes[0];
goto testlist_comp;
@@ -495,7 +494,7 @@
case PN_atom_bracket:
// lhs is something in brackets
if (assign_kind != ASSIGN_STORE) {
- goto bad_aug;
+ goto cannot_assign;
}
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// empty list, assignment allowed
@@ -543,10 +542,6 @@
cannot_assign:
compile_syntax_error(comp, pn, "can't assign to expression");
- return;
-
- bad_aug:
- compile_syntax_error(comp, pn, "illegal expression for augmented assignment");
}
// stuff for lambda and comprehensions and generators: