diff options
author | PMunch <peterme@peterme.net> | 2020-05-12 20:28:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 20:28:18 +0200 |
commit | 9acbf99efb42d7d3f98f3d1d6677923fc4dd3a28 (patch) | |
tree | 285412bf78787fd66f2719c84eacf0f6d1bd90a4 /tests/let/timportc.nim | |
parent | 82f008158cbc023c5e20103bfb4bda317be52fb2 (diff) | |
download | Nim-9acbf99efb42d7d3f98f3d1d6677923fc4dd3a28.tar.gz |
Allow let to not have value when using importc (#14258)
* Allow let to not have value when using importc This allows a let statement with the `{.importc.}` pragma to not be initialised with a value. This allows us to declare C constants as Nim lets without putting the value in the Nim code (which can lead to errors, and requires us to go looking for the value). Fixes #14253 * Proper fix and documentation + changelog entry * Improve testcase with one from timotheecour * Add test to verify it working with macros
Diffstat (limited to 'tests/let/timportc.nim')
-rw-r--r-- | tests/let/timportc.nim | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/let/timportc.nim b/tests/let/timportc.nim new file mode 100644 index 000000000..85244da9f --- /dev/null +++ b/tests/let/timportc.nim @@ -0,0 +1,24 @@ +discard """ +targets: "c cpp js" +""" + +when defined(c) or defined(cpp): + {.emit:""" + const int TEST1 = 123; + #define TEST2 321 + """.} + +when defined(js): + {.emit:""" + const TEST1 = 123; + const TEST2 = 321; // JS doesn't have macros, so we just duplicate + """.} + +let + TEST0 = 1 + TEST1 {.importc, nodecl.}: cint + TEST2 {.importc, nodecl.}: cint + +doAssert TEST0 == 1 +doAssert TEST1 == 123 +doAssert TEST2 == 321 |