Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/umka_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,10 @@ void parseDesignatorList(Umka *umka, const Type **type, Const *constant, bool *i

lexNext(&umka->lex);

// Not a designator list, but a short variable declaration with a non-identifier on the left, e.g., a[0], b := f()
if (doShortVarDeclLookahead(umka))
umka->error.handler(umka->error.context, "Identifier expected on the left side of :=");

bool fieldIsVar, fieldIsCall, fieldIsCompLit;
parseDesignator(umka, &fieldType, NULL, &fieldIsVar, &fieldIsCall, &fieldIsCompLit, NULL);

Expand Down
5 changes: 4 additions & 1 deletion src/umka_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void doResolveExtern(Umka *umka)
}


static bool doShortVarDeclLookahead(Umka *umka)
bool doShortVarDeclLookahead(Umka *umka)
{
// ident {"," ident} ":="
Lexer lookaheadLex = umka->lex;
Expand Down Expand Up @@ -410,6 +410,9 @@ static void parseSimpleStmt(Umka *umka)

TokenKind op = umka->lex.tok.kind;

if (op == TOK_COLONEQ)
umka->error.handler(umka->error.context, "Identifier expected on the left side of :=");

if (typeExprListStruct(type) && !isCall && op != TOK_EQ)
umka->error.handler(umka->error.context, "List assignment expected");

Expand Down
1 change: 1 addition & 0 deletions src/umka_stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

void doZeroVar(Umka *umka, const Ident *ident);
void doResolveExtern(Umka *umka);
bool doShortVarDeclLookahead(Umka *umka);

void parseAssignmentStmt(Umka *umka, const Type *type, Const *varPtrConstList);
void parseDeclAssignmentStmt(Umka *umka, IdentName *names, const bool *exported, int num, bool constExpr);
Expand Down
13 changes: 13 additions & 0 deletions tests/negative.um
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ fn main() {
s[0] = 'x'
}`},

{.compileError, "Identifier expected on the left side of :=", `
fn f(): (int, bool) {return 42, true}
fn main() {
a := [2]int{5, 7}
a[0], ok := f()
}`},

{.compileError, "Identifier expected on the left side of :=", `
fn main() {
a := [2]int{5, 7}
a[0] := 1
}`},

{.compileError, "Constant must be ordinal, or real, or string, or closure", `
const c = []int{1}
fn main() {}`},
Expand Down