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

Nim v2.2.0 and v2.2.2: Compilation Error When Using Template Parameter in Default Argument for Array/Sequence #24672

Open
Clemente90 opened this issue Feb 7, 2025 · 1 comment · May be fixed by #24497

Comments

@Clemente90
Copy link

Clemente90 commented Feb 7, 2025

Description

I had a project that was compiling fine in v2.0.0.
I upgraded to v.2.2.0 and the compiler would segfault with:

Error: internal error: invalid kind for floatRangeCheck:tyGenericParam                                                                                                                      
SIGSEGV: Illegal storage access. (Attempt to read from nil?

I upgraded to v.2.2.2 and now get this :

Error: type mismatch:
 got 'typeof(T.high)' for 'T.high' [fromExpr]
 but expected 'typeof(T.high)' [fromExpr]

I was able to construct an example:

func initArray[T](arg: array[1, T] = [T.high]): array[1, T] =
  return arg

echo initArray[float]()  # this would compile and print [inf] in previous versions.

This bug at least affects arrays and seq's, however this still works:

func initValue[T](arg: T = T.high): T =
  return arg

echo initValue[float]()  # this compiles and prints inf.

Also note that things like 100.0.T will not compile but a default value of just 100.0 will compile.

Nim Version

v2.0.0 works

v2.2.0 and v2.2.2 do not work

Current Output

Error: type mismatch:
 got 'typeof(T.high)' for 'T.high' [fromExpr]
 but expected 'typeof(T.high)' [fromExpr]

Expected Output

[inf]

Known Workarounds

No response

Additional Information

Compiled on Linux with GCC using the C or C++ backends and ORC.

@Clemente90 Clemente90 changed the title "Nim v2.2.0 and v2.2.2: Compilation Error When Using Template Parameter in Default Argument for Array/Sequence" Nim v2.2.0 and v2.2.2: Compilation Error When Using Template Parameter in Default Argument for Array/Sequence Feb 7, 2025
@metagn
Copy link
Collaborator

metagn commented Feb 7, 2025

Same issue as #24484, fix in #24497

metagn added a commit to metagn/Nim that referenced this issue Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants