mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 13:07:48 +00:00
fix isNil folding for compile time closures (#22574)
fixes #20543
(cherry picked from commit bd6adbcc9d)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user