fix isNil folding for compile time closures (#22574)

fixes #20543

(cherry picked from commit bd6adbcc9d)
This commit is contained in:
metagn
2023-09-02 11:32:46 +03:00
committed by narimiran
parent 45aa0a4725
commit 70d771d1a9
2 changed files with 15 additions and 1 deletions

View File

@@ -230,7 +230,13 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): P
of mMulF64: result = newFloatNodeT(getFloat(a) * getFloat(b), n, g)
of mDivF64:
result = newFloatNodeT(getFloat(a) / getFloat(b), n, g)
of mIsNil: result = newIntNodeT(toInt128(ord(a.kind == nkNilLit)), n, idgen, g)
of mIsNil:
let val = a.kind == nkNilLit or
# nil closures have the value (nil, nil)
(a.typ != nil and skipTypes(a.typ, abstractRange).kind == tyProc and
a.kind == nkTupleConstr and a.len == 2 and
a[0].kind == nkNilLit and a[1].kind == nkNilLit)
result = newIntNodeT(toInt128(ord(val)), n, idgen, g)
of mLtI, mLtB, mLtEnum, mLtCh:
result = newIntNodeT(toInt128(ord(getOrdValue(a) < getOrdValue(b))), n, idgen, g)
of mLeI, mLeB, mLeEnum, mLeCh:

View File

@@ -229,6 +229,14 @@ block: # bug #15595
static: main()
main()
block: # issue #20543
type F = proc()
const myArray = block:
var r: array[1, F]
r[0] = nil
r
doAssert isNil(myArray[0])
# bug #15363
import sequtils