We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A compile time block in a function body doesn't allow the creation of vars. The following example fails to compile:
func stuff(): int = const r = block: var r = 0 # Error: cannot evaluate at compile time: r for i in 0..10: r *= i r r echo stuff()
When the const block is outside the function, it works however:
const r = block: var r = 0 for i in 0..10: r *= i r func stuff(): int = r echo stuff()
Nim Compiler Version 1.9.3 [Linux: amd64] Compiled at 2023-04-01 Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 1c7fd71 active boot switches: -d:release
Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf] Hint: used config file '/home/tsoj/.choosenim/toolchains/nim-#devel/config/config.nims' [Conf] ...................................................................... /tmp/main.nim(3, 9) Error: cannot evaluate at compile time: r
0 or if it's supposed to not compile, a better error message.
No response
The text was updated successfully, but these errors were encountered:
Similar/same #8758 #10828 #12172
Sorry, something went wrong.
push block label sym owner for const and static
const
static
574ef53
fixes nim-lang#8758, fixes nim-lang#10828, fixes nim-lang#12172, fixes nim-lang#21610, fixes nim-lang#23803, refs nim-lang/RFCs#276
5399f3e
Successfully merging a pull request may close this issue.
Description
A compile time block in a function body doesn't allow the creation of vars. The following example fails to compile:
When the const block is outside the function, it works however:
Nim Version
Nim Compiler Version 1.9.3 [Linux: amd64]
Compiled at 2023-04-01
Copyright (c) 2006-2023 by Andreas Rumpf
git hash: 1c7fd71
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: