With the following code
# macro m(n:typed):untyped = n.copy # Error with Nim version 0.14.2 and the devel branch
macro m(n:typed):untyped = n # Error with the devel branch but not version 0.14.2
U = object
V = object
proc ``(x:var U,y:int):var float = x.v[y]
template `+=`(x:var V,y:V):untyped = x.v+=y.v
template `+=`(x:V,y:V):untyped = x.v+=y.v
x+=y # compiles
x+=y # Error: type mismatch: got (var float, system.float)
The devel branch errors with
t_peq_template.nim(10, 44) Error: type mismatch: got (var float, system.float)
but expected one of:
proc `+=`[T: float | float32 | float64](x: var T; y: T)
for a 'var' type a variable needs to be passed, but 'x.v' is immutable
Note that if you comment out the trivial macro call of m, it compiles. I guess some type checking mechanism in the compiler vm after a call of macro is incorrect.
In addition, if in the macro definition copy is called, the release version 0.14.2 of the compiler also errors with the same error message from the devel branch.
I'm still hitting this bug with 0.15.0.
Does anyone have some idea as to where in the compiler source I should poke at?
Or any workaround as to what in the macro I can do to circumvent this issue?
Hmm sorry, this should have been marked as 'regression' to get a higher priority.
Did a bisect, and found out the offending commit, e73fd64, is a relative short patch, but I'm not very familiar with the semantic check. Is there a document about the semantic check part of the compiler? Which part of the code do you recommend for me to start looking at?