Don't crash for invalid toplevel parseStmt/Expr calls (#23089)

This code will crash `check`/`nimsuggest` since the `ra` register is
uninitialised

```nim
import macros

static:
  discard parseExpr("'")
```
Now it assigns an empty node so that it has something

Testament changes were so I could properly write a test. It would pass
even with a segfault since it could find the error
This commit is contained in:
Jake Leahy
2023-12-20 03:27:24 +11:00
committed by GitHub
parent 6618448ced
commit db9d8003b0
3 changed files with 27 additions and 4 deletions

View File

@@ -1925,6 +1925,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
proc (conf: ConfigRef; info: TLineInfo; msg: TMsgKind; arg: string) =
if error.len == 0 and msg <= errMax:
error = formatMsg(conf, info, msg, arg))
regs[ra].node = newNode(nkEmpty)
if error.len > 0:
c.errorFlag = error
elif ast.len != 1:
@@ -1942,6 +1944,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
error = formatMsg(conf, info, msg, arg))
if error.len > 0:
c.errorFlag = error
regs[ra].node = newNode(nkEmpty)
else:
regs[ra].node = ast
of opcQueryErrorFlag: