From 4fdc6c49bd2a9085d40590bd9ba9696b1e6066d9 Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Thu, 7 Dec 2023 18:14:23 +1100 Subject: 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 --- tests/pragmas/tinvalid_user_pragma.nim | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/pragmas/tinvalid_user_pragma.nim (limited to 'tests/pragmas') diff --git a/tests/pragmas/tinvalid_user_pragma.nim b/tests/pragmas/tinvalid_user_pragma.nim new file mode 100644 index 000000000..3081db842 --- /dev/null +++ b/tests/pragmas/tinvalid_user_pragma.nim @@ -0,0 +1,9 @@ +discard """ +cmd: "nim check $file" +""" + +{.pragma test: foo.} #[tt.Error +^ invalid pragma: {.pragma, test: foo.} ]# + +{.pragma: 1.} #[tt.Error +^ invalid pragma: {.pragma: 1.} ]# -- cgit 1.4.1-2-gfad0