summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semfold.nim8
-rw-r--r--tests/vm/tvmmisc.nim8
2 files changed, 15 insertions, 1 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim
index c6dec09a9..f1a1c8a82 100644
--- a/compiler/semfold.nim
+++ b/compiler/semfold.nim
@@ -241,7 +241,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:
diff --git a/tests/vm/tvmmisc.nim b/tests/vm/tvmmisc.nim
index 1429ef6e9..cade68577 100644
--- a/tests/vm/tvmmisc.nim
+++ b/tests/vm/tvmmisc.nim
@@ -232,6 +232,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
 
am?id=0d15c7108d4ffc82fc2bbc1c2c894bc6ff782841'>0d15c710 ^
4dc48b4b ^
1809064d ^
c1ee75da ^
2490f5b4 ^
36265dde ^

92837ec1 ^
c1ee75da ^



21ab1821 ^
c1ee75da ^
264fc55a ^
d782b007 ^
0fbaa6f5 ^
7842b0d1 ^
107fdd35 ^




b9119b43 ^

107fdd35 ^
2490f5b4 ^
107fdd35 ^

92837ec1 ^
107fdd35 ^


447d2358 ^
21ab1821 ^
107fdd35 ^

0d15c710 ^

6a9e1930 ^
9aa282f6 ^

0d15c710 ^
8c01021a ^
5be9ac32 ^
8c01021a ^
5be9ac32 ^
8c01021a ^
0d15c710 ^
2451b7b1 ^
8b4c7e93 ^
3487100c ^
5319a03a ^
aa4ffa7e ^
419f37fe ^
7db1bcee ^
a871ad80 ^
003002d6 ^
0d15c710 ^
d782b007 ^


0fbaa6f5 ^
d782b007 ^
fa89e2aa ^
0d15c710 ^
fa89e2aa ^

0d15c710 ^
264fc55a ^
0c1092fd ^

1809064d ^

0c1092fd ^
3ceb9b0d ^
fa89e2aa ^
7e4b1b1d ^
0fbaa6f5 ^
fa89e2aa ^

0fbaa6f5 ^
fa89e2aa ^
264fc55a ^

d782b007 ^
0fbaa6f5 ^
3ceb9b0d ^



0fbaa6f5 ^


d782b007 ^


0fbaa6f5 ^
e2f37600 ^
2655d9e8 ^
0c1092fd ^

01394d6c ^
0fbaa6f5 ^

0c1092fd ^

13ee16de ^
0fbaa6f5 ^


















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146