Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix infinite recursion in typeRel #15241

Merged
merged 19 commits into from
Sep 18, 2020
2 changes: 1 addition & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,

template considerPreviousT(body: untyped) =
var prev = PType(idTableGet(c.bindings, f))
if prev == nil: body
if prev == nil or prev == f: body
Araq marked this conversation as resolved.
Show resolved Hide resolved
else: return typeRel(c, prev, a)

case a.kind
Expand Down
19 changes: 19 additions & 0 deletions tests/overload/toverload_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ block:
template t0(x: Bar[int]): int = 1
template t0(x: Foo[bool or int]): int = 10
template t0(x: Bar[bool or int]): int = 11
#template t0[T:bool or int](x: Bar[T]): int = 11
template t0[T](x: Foo[T]): int = 20
template t0[T](x: Bar[T]): int = 21
proc p0(x: Foo[int]): int = 0
Expand Down Expand Up @@ -461,3 +462,21 @@ block:
doAssert(p0(g) == 20)
doAssert(p0(h) == 21)
doAssert(p0(i) == 21)

#type
# f0 = proc(x:Foo)

block:
type
TilesetCT[n: static[int]] = distinct int
TilesetRT = int
Tileset = TilesetCT | TilesetRT

func prepareTileset(tileset: var Tileset) = discard

func prepareTileset(tileset: Tileset): Tileset =
result = tileset
result.prepareTileset

var parsedTileset: TilesetRT
prepareTileset(parsedTileset)