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

Compiler crash on template evaluation for generic static int #24044

Closed
arnetheduck opened this issue Sep 2, 2024 · 1 comment · Fixed by #24049
Closed

Compiler crash on template evaluation for generic static int #24044

arnetheduck opened this issue Sep 2, 2024 · 1 comment · Fixed by #24049
Assignees

Comments

@arnetheduck
Copy link
Contributor

arnetheduck commented Sep 2, 2024

Description

type ArrayBuf*[N: static int, T = byte] = object
  buf: array[N, T]

template maxLen(T: type): int =
  sizeof(T) * 2

type MyBuf[I] = ArrayBuf[maxLen(I)]

var v: MyBuf[int]

same as #24043, but with a template

Nim Version

2.0.8

Current Output

nim c -r "testit.nim"
.......................................................................................................................SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

Expected Output

No response

Known Workarounds

No response

Additional Information

No response

@arnetheduck
Copy link
Contributor Author

workaround: be explicit about T

type ArrayBuf*[N: static int, T] = object
  buf: array[N, T]

template maxLen(T: type): int =
  sizeof(T) * 2

type MyBuf[I: type] = ArrayBuf[maxLen(I), byte]

var v: MyBuf[int]

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.

3 participants