Skip to content

Compiler crash with empty array and generic instantiation with int as parameter #12264

Closed
@liquidev

Description

@liquidev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions