Disallow nil dereference at compile time (#16032)
* bring back the semfold of nil * remove space * fix test * proc type can't be dereferenced * disallow nil dereference at compile time * changelog
This commit is contained in:
parent
bf8421a2fc
commit
acf8316e50
4 changed files with 12 additions and 2 deletions
|
|
@ -671,6 +671,10 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode
|
|||
var a = getConstExpr(m, n[1], idgen, g)
|
||||
if a == nil: return
|
||||
result = foldConv(n, a, g, check=true)
|
||||
of nkDerefExpr, nkHiddenDeref:
|
||||
let a = getConstExpr(m, n[0], idgen, g)
|
||||
if a != nil and a.kind == nkNilLit:
|
||||
localError(g.config, n.info, "nil dereference is not allowed")
|
||||
of nkCast:
|
||||
var a = getConstExpr(m, n[1], idgen, g)
|
||||
if a == nil: return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue