passing {} to a template loses type information, giving an error
type Foo = enum k1, k2
proc main()=
# macro fun(opts: static set[Foo]) = # works
# proc fun(opts: set[Foo]) = # works
template fun(opts: set[Foo]) =
discard opts + {k2}
fun({})
main()
Error: type mismatch: got <set[empty], set[Foo]>
should compile, as it does with macro or proc (see example)
Similar issue with empty seq:
proc main()=
template fun(opts: seq[int]) =
discard opts
fun(@[])
which gives:
Error: type mismatch: got <seq[empty], string, string, string>
propagate type information when template argument provides a type; the template already does type checking when passing arguments to it and during overload resolution, but the type information gets lost after that
nim -v).Nim Compiler Version 0.20.99 [MacOSX: amd64]
Compiled at 2019-06-25
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: 0d50b0c8a766a80c357edfcdda563f239caaf9e6
active boot switches: -d:release
potentially related (but different issue): https://github.com/nim-lang/Nim/issues/7117
Yay, @timotheecour, welcome back!
Most helpful comment
Yay, @timotheecour, welcome back!