Skip to content
New issue

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

Error "cannot evaluate at compile time" for blocks returning const values #23803

Open
alex65536 opened this issue Jul 6, 2024 · 1 comment · May be fixed by #24085
Open

Error "cannot evaluate at compile time" for blocks returning const values #23803

alex65536 opened this issue Jul 6, 2024 · 1 comment · May be fixed by #24085

Comments

@alex65536
Copy link
Contributor

Description

# error: cannot evaluate at compile time: res
func foo1*(c: int): int {.inline.} =
  const arr = block:
    var res: array[0..99, int]
    res[42] = 43
    res
  arr[c]

# works
func foo2*(c: int): int {.inline.} =
  func initArr(): auto =
    var res: array[0..99, int]
    res[42] = 43
    res
  const arr = initArr()
  arr[c]

# also works
const globalArr = block:
  var res: array[0..99, int]
  res[42] = 43
  res
func foo3*(c: int): int {.inline.} = globalArr[c]

Nim Version

Reproducible both on 2.0.8 and devel

Current Output

repro.nim(4, 9) Error: cannot evaluate at compile time: res

Expected Output

*compiles and runs successfully*

Possible Solution

No response

Additional Information

No response

@alex65536
Copy link
Contributor Author

Possibly related to #8758.

@alex65536 alex65536 changed the title Error "cannot evaluate at compile time" for blocks returning const arrays Error "cannot evaluate at compile time" for blocks returning const values Jul 6, 2024
@metagn metagn linked a pull request Sep 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant