Prevent the construction of recursive tyStatic types (#9256)

Fixes #9255

(cherry picked from commit b8d2f79ef0)
This commit is contained in:
LemonBoy
2018-10-09 14:26:34 +02:00
committed by narimiran
parent ffeb3c6cec
commit ddd54a3413
2 changed files with 20 additions and 4 deletions

View File

@@ -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:

View File

@@ -0,0 +1,13 @@
discard """
errormsg: '''
type mismatch: got <static[proc (a0: int): string{.noSideEffect, gcsafe, locks: 0.}](bar)>
'''
line: 13
"""
macro fun(a: static float): untyped =
discard
when isMainModule:
proc bar(a0: int): string = discard
fun(bar)