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 with empty array and generic instantiation with int as parameter #12264

Closed
liquidev opened this issue Sep 25, 2019 · 0 comments
Closed

Comments

@liquidev
Copy link
Contributor

liquidev commented Sep 25, 2019

The compiler crashes with the following example, where FloatGen is defined as an alias to Gen[float, 8].

Example

type
  Gen[T; U: int] = object
    a: array[U, T]
 
proc initGen[T; U: int](): Gen[T, U] =
  result = Gen[T, U]()
  result.a = []

type
  FloatGen = Gen[float, 8] # this makes the compiler crash

var gen = initGen[float, 8]()
echo gen

Current Output

fatal.nim(39)            sysFatal
Error: unhandled exception: int128.nim(72, 11) `arg.sdata(2) == 0` out of range [AssertionError]

Expected Output

This is the output when the type alias is removed, it's also the expected error message.

/usercode/in.nim(9, 18) template/generic instantiation of `initGen` from here
/usercode/in.nim(7, 14) Error: type mismatch: got <array[0..-1, empty]> but expected 'array[int, float]'

Additional Information

$ nim -v
Nim Compiler Version 1.0.0 [Linux: amd64]
Compiled at 2019-09-23
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: f7a8fc46c0012033917582eb740dc0343c093e35
active boot switches: -d:release
Araq added a commit that referenced this issue Sep 30, 2019
@Araq Araq closed this as completed in dd082b6 Sep 30, 2019
narimiran pushed a commit that referenced this issue Oct 3, 2019
(cherry picked from commit dd082b6)
rayman22201 pushed a commit to rayman22201/Nim that referenced this issue Oct 4, 2019
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

No branches or pull requests

1 participant