diff --git a/src/compiler.h b/src/compiler.h index d8660a4d..52b459fb 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -359,21 +359,24 @@ private: // PASS void exprList() { - auto e = expr_prev_line(); + int line = prev().line; + std::vector items; do { match_newlines(mode()==REPL_MODE); if (curr().type == TK("]")) break; EXPR(); - e->items.push_back(ctx()->s_expr.popx()); + items.push_back(ctx()->s_expr.popx()); match_newlines(mode()==REPL_MODE); - if(e->items.size()==1 && match(TK("for"))){ - _consume_comp(std::move(e->items[0])); + if(items.size()==1 && match(TK("for"))){ + _consume_comp(std::move(items[0])); consume(TK("]")); return; } match_newlines(mode()==REPL_MODE); } while (match(TK(","))); consume(TK("]")); + auto e = expr_prev_line(std::move(items)); + e->line = line; // override line ctx()->s_expr.push(std::move(e)); } diff --git a/src/expr.h b/src/expr.h index 7106f82a..f08e671d 100644 --- a/src/expr.h +++ b/src/expr.h @@ -269,6 +269,7 @@ struct SliceExpr: Expr{ struct SequenceExpr: Expr{ std::vector items; + SequenceExpr(std::vector&& items): items(std::move(items)) {} virtual Opcode opcode() const = 0; void emit(CodeEmitContext* ctx) override {