mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
Prevent the construction of recursive tyStatic types (#9256)
Fixes #9255
(cherry picked from commit b8d2f79ef0)
This commit is contained in:
@@ -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:
|
||||
|
||||
13
tests/statictypes/t9255.nim
Normal file
13
tests/statictypes/t9255.nim
Normal 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)
|
||||
Reference in New Issue
Block a user