* fix #15623

* add testcase for #15623

* fix

* add testcase
This commit is contained in:
flywind
2020-11-18 01:05:20 +08:00
committed by GitHub
parent fec19c980e
commit 0f7f159a35
4 changed files with 26 additions and 2 deletions

View File

@@ -674,7 +674,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
of nkCast:
var a = getConstExpr(m, n[1], idgen, g)
if a == nil: return
if n.typ != nil and n.typ.kind in NilableTypes:
if n.typ != nil and n.typ.kind in NilableTypes and a.kind != nkNilLit:
# we allow compile-time 'cast' for pointer types:
result = a
result.typ = n.typ

View File

@@ -365,7 +365,7 @@ const SCHED_RR* = cint(2)
const SCHED_OTHER* = cint(0)
# <semaphore.h>
const SEM_FAILED* = cast[pointer]((nil))
const SEM_FAILED* = nil
# <signal.h>
const SIGEV_NONE* = cint(1)

11
tests/ccgbugs/t15623.nim Normal file
View File

@@ -0,0 +1,11 @@
discard """
action: "compile"
"""
# bug #15623
block:
echo cast[ptr int](nil)[]
block:
var x: ref int = nil
echo cast[ptr int](x)[]

View File

@@ -0,0 +1,13 @@
discard """
output: '''0
0
'''
"""
# bug #15623
block:
echo cast[int](cast[ptr int](nil))
block:
var x: ref int = nil
echo cast[int](cast[ptr int](x))