Semfold for nil cast (#16030)
* bring back the semfold of nil * remove space * fix test * proc type can't be dereferenced
This commit is contained in:
parent
33d79b9e64
commit
87d3e5331a
3 changed files with 8 additions and 5 deletions
|
|
@ -71,8 +71,10 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
p.module.s[cfsData].addf(
|
p.module.s[cfsData].addf(
|
||||||
"static NIM_CONST $1 $2 = {NIM_NIL,NIM_NIL};$n",
|
"static NIM_CONST $1 $2 = {NIM_NIL,NIM_NIL};$n",
|
||||||
[getTypeDesc(p.module, ty), result])
|
[getTypeDesc(p.module, ty), result])
|
||||||
else:
|
elif k in {tyPointer, tyNil, tyProc}:
|
||||||
result = rope("NIM_NIL")
|
result = rope("NIM_NIL")
|
||||||
|
else:
|
||||||
|
result = "(($1) NIM_NIL)" % [getTypeDesc(p.module, ty)]
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
let k = if ty == nil: tyString
|
let k = if ty == nil: tyString
|
||||||
else: skipTypes(ty, abstractVarRange + {tyStatic, tyUserTypeClass, tyUserTypeClassInst}).kind
|
else: skipTypes(ty, abstractVarRange + {tyStatic, tyUserTypeClass, tyUserTypeClassInst}).kind
|
||||||
|
|
|
||||||
|
|
@ -674,7 +674,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
|
||||||
of nkCast:
|
of nkCast:
|
||||||
var a = getConstExpr(m, n[1], idgen, g)
|
var a = getConstExpr(m, n[1], idgen, g)
|
||||||
if a == nil: return
|
if a == nil: return
|
||||||
if n.typ != nil and n.typ.kind in NilableTypes and a.kind != nkNilLit:
|
if n.typ != nil and n.typ.kind in NilableTypes:
|
||||||
# we allow compile-time 'cast' for pointer types:
|
# we allow compile-time 'cast' for pointer types:
|
||||||
result = a
|
result = a
|
||||||
result.typ = n.typ
|
result.typ = n.typ
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ block:
|
||||||
static:
|
static:
|
||||||
doAssert cast[RootRef](nil).repr == "nil"
|
doAssert cast[RootRef](nil).repr == "nil"
|
||||||
|
|
||||||
block:
|
# Issue #15730, not fixed yet
|
||||||
static:
|
# block:
|
||||||
doAssert cast[cstring](nil).repr == "nil"
|
# static:
|
||||||
|
# doAssert cast[cstring](nil).repr == "nil"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue