i have a piece of code which i managed to reduce to this minimal form
import sequtils
type
Color1 = array[1, int]
Color2 = array[1, int]
Color = Color1 | Color2
Image1 = seq[seq[Color1]]
Image2 = seq[seq[Color2]]
Image = Image1 | Image2
template b(c: Color) = discard
proc appl(img: Image, k: seq[seq[int]]) =
echo k.foldl(a + b.foldl(a + b), 0)
appl @[@[[1]]], @[@[0]]
which fails to compile with
.nim(16, 1) template/generic instantiation from here
in.nim(14, 20) Error: 'b' has unspecified generic parameters
im probably doing something wrong with template, but if i would change the signature of the appl proc from Image to Image1 or any other type it works normally. and why the b from foldl gets confused with template. sorry if im being a brainlet and missing something obvious.
This looks like a bug. Somehow the generic proc instantiation of appl makes the compiler mess with the untyped paramter to foldl. Here is a smaller example:
import sequtils
template b = 0
proc bar[T](): int =
foldl(@[1,2,3], a + b, 0)
echo bar[int]() # 0
I'm not really sure if I would consider that a bug.
b is a bad name for a proc/template anyway. An ambiguous call might improve this though.
this works:
import sequtils
type
Color1 = array[1, int]
Color2 = array[1, int]
Color = Color1 | Color2
Image1 = seq[seq[Color1]]
Image2 = seq[seq[Color2]]
Image = Image1 | Image2
template foo(c: Color) = discard
proc appl(img: Image, k: seq[seq[int]]) =
echo k.foldl(a + b.foldl(a + b), 0)
appl @[@[[1]]], @[@[0]]
Here is a more scary example with the tables module:
import tables
var value: string
var table = initTable[int, int]()
table[1] = 1
proc foo[T]() =
table.withValue(1, value) do: discard
foo[int]()
Fails with inconsistent typing for reintroduced symbol 'value': previous type was: string; new type is: ptr int