-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
discard """ | ||
errormsg: "'let' symbol requires an initialization" | ||
line: "7" | ||
""" | ||
|
||
# Test that this still works when not annotated with importc | ||
let test: cint | ||
echo test |