diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index cc1aaa074d..f97ae25b73 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1911,10 +1911,13 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, else: var evaluated = c.semTryConstExpr(c, arg) if evaluated != nil: - arg.typ = newTypeS(tyStatic, c) - arg.typ.sons = @[evaluated.typ] - arg.typ.n = evaluated - a = arg.typ + # Don't build the type in-place because `evaluated` and `arg` may point + # to the same object and we'd end up creating recursive types (#9255) + let typ = newTypeS(tyStatic, c) + typ.sons = @[evaluated.typ] + typ.n = evaluated + arg.typ = typ + a = typ else: if m.callee.kind == tyGenericBody: if f.kind == tyStatic and typeRel(m, f.base, a) != isNone: diff --git a/tests/statictypes/t9255.nim b/tests/statictypes/t9255.nim new file mode 100644 index 0000000000..bc8df66568 --- /dev/null +++ b/tests/statictypes/t9255.nim @@ -0,0 +1,13 @@ +discard """ + errormsg: ''' +type mismatch: got +''' + line: 13 +""" + +macro fun(a: static float): untyped = + discard + +when isMainModule: + proc bar(a0: int): string = discard + fun(bar)