From 2ee57b3e6d063fe7c675429a10e06720459b08fe Mon Sep 17 00:00:00 2001 From: zerbina <100542850+zerbina@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:40:57 +0000 Subject: [PATCH] sem: fix error propagation for tuple construction Summary ======= * fix errors in anonymous tuple constructions not being propagated * fix the error for colon expressions in anonymous tuple constructions being "invalid expression" instead of "named expression not allowed here" Details ======= * properly propagate errors from element expressions * don't analyze `nkExprColonExpr` as a normal expression * don't modify input AST * skip tuple type constructor analysis if any of the element expressions is erroneous --- compiler/sem/semexprs.nim | 54 ++++++++++++++++++++-------------- tests/errmsgs/tmixed_tuple.nim | 7 +++++ 2 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 tests/errmsgs/tmixed_tuple.nim diff --git a/compiler/sem/semexprs.nim b/compiler/sem/semexprs.nim index e98531714e9..66dbc8bac7e 100644 --- a/compiler/sem/semexprs.nim +++ b/compiler/sem/semexprs.nim @@ -3148,39 +3148,49 @@ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = "expected nkTupleConstr, got: " & $n.kind) let - tupExp = n # we don't modify n, but compute the type: + tupExp = shallowCopy(n) typ = newTypeS(tyTuple, c) # leave typ.n nil! - for i in 0.. 0: # don't interpret () as type - isTupleType = tupExp[0].typ.kind == tyTypeDesc + let isTupleType = tupExp[0].typ.kind == tyTypeDesc # check if either everything or nothing is tyTypeDesc for i in 1..