Skip to content

Instantly share code, notes, and snippets.

@gmpreussner
Last active August 29, 2015 14:12
Show Gist options
  • Save gmpreussner/a1ebb01db395be2529e6 to your computer and use it in GitHub Desktop.
Save gmpreussner/a1ebb01db395be2529e6 to your computer and use it in GitHub Desktop.
# this works ##########################
type
Foo[N: static[int], T] = object
elements: array[0..(N - 1), T]
var f2 = Foo[2, float](elements: [1.0, 2.0])
var f3 = Foo[3, float](elements: [1.0, 2.0, 3.0])
# this fails ##########################
type
FooTypes = enum
Fubar,
Snafu,
Tarfu
Foo[N: static[int], T; BT: static[FooTypes]] = object
elements: array[0..(N - 1), T]
var f2s = Foo[2, float, FooTypes.Snafu](elements: [1.0, 2.0])
var f2t = Foo[2, float, FooTypes.Tarfu](elements: [1.0, 2.0]) # Error: internal error: genObjConstr
@gmpreussner
Copy link
Author

I did some more tests. It looks like this problem only occurs if the proc signature is NOT fully qualified with all generic params. The example above can be fixed by rewriting 'foobar' as follows:

#proc foobar(f: Foo) =
# this works:
proc foobar[N, T, BT](f: Foo[N, T, BT]) =
  echo f.elements[0]

I have verified this with several other examples in my code base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment