diff options
author | Jake Leahy <jake@leahy.dev> | 2023-12-07 18:14:23 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 08:14:23 +0100 |
commit | 4fdc6c49bd2a9085d40590bd9ba9696b1e6066d9 (patch) | |
tree | 3d5db38ed964eafe21c498323d7b425eb0920c0f /compiler | |
parent | e1a0ff1b8a5b84f4e9e338691b280678bc03f650 (diff) | |
download | Nim-4fdc6c49bd2a9085d40590bd9ba9696b1e6066d9.tar.gz |
Don't process a user pragma if its invalid (#23041)
When running `check`/`suggest` in a file with an invalid user pragma like ```nim {.pragma foo: test.} ``` It will continue to try and process it which leads to the compiler running into a `FieldDefect` ``` fatal.nim(53) sysFatal Error: unhandled exception: field 'sons' is not accessible for type 'TNode' using 'kind = nkIdent' [FieldDefect] ``` This makes it instead bail out trying to process the user pragma if its invalid
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/pragmas.nim | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index a800edaf8..fe4ef2b87 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -685,9 +685,12 @@ proc pragmaLine(c: PContext, n: PNode) = proc processPragma(c: PContext, n: PNode, i: int) = ## Create and add a new custom pragma `{.pragma: name.}` node to the module's context. let it = n[i] - if it.kind notin nkPragmaCallKinds and it.safeLen == 2: invalidPragma(c, n) + if it.kind notin nkPragmaCallKinds and it.safeLen == 2: + invalidPragma(c, n) + return elif it.safeLen != 2 or it[0].kind != nkIdent or it[1].kind != nkIdent: invalidPragma(c, n) + return var userPragma = newSym(skTemplate, it[1].ident, c.idgen, c.module, it.info, c.config.options) styleCheckDef(c, userPragma) |