allow 'nil ref T' as a first step which does nothing
This commit is contained in:
parent
0dcaf27b64
commit
a2480efd68
2 changed files with 19 additions and 9 deletions
|
|
@ -135,13 +135,19 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
|
||||||
checkMinSonsLen(n, 1)
|
checkMinSonsLen(n, 1)
|
||||||
var base = semTypeNode(c, n.lastSon, nil)
|
var base = semTypeNode(c, n.lastSon, nil)
|
||||||
result = newOrPrevType(kind, prev, c)
|
result = newOrPrevType(kind, prev, c)
|
||||||
|
var isNilable = false
|
||||||
# check every except the last is an object:
|
# check every except the last is an object:
|
||||||
for i in isCall .. n.len-2:
|
for i in isCall .. n.len-2:
|
||||||
let region = semTypeNode(c, n[i], nil)
|
let ni = n[i]
|
||||||
if region.skipTypes({tyGenericInst}).kind notin {tyError, tyObject}:
|
if ni.kind == nkNilLit:
|
||||||
message n[i].info, errGenerated, "region needs to be an object type"
|
isNilable = true
|
||||||
addSonSkipIntLit(result, region)
|
else:
|
||||||
|
let region = semTypeNode(c, ni, nil)
|
||||||
|
if region.skipTypes({tyGenericInst}).kind notin {tyError, tyObject}:
|
||||||
|
message n[i].info, errGenerated, "region needs to be an object type"
|
||||||
|
addSonSkipIntLit(result, region)
|
||||||
addSonSkipIntLit(result, base)
|
addSonSkipIntLit(result, base)
|
||||||
|
#if not isNilable: result.flags.incl tfNotNil
|
||||||
|
|
||||||
proc semVarType(c: PContext, n: PNode, prev: PType): PType =
|
proc semVarType(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if sonsLen(n) == 1:
|
if sonsLen(n) == 1:
|
||||||
|
|
@ -1169,6 +1175,14 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = semTypeNode(c, b, prev)
|
result = semTypeNode(c, b, prev)
|
||||||
elif ident != nil and ident.id == ord(wDotDot):
|
elif ident != nil and ident.id == ord(wDotDot):
|
||||||
result = semRangeAux(c, n, prev)
|
result = semRangeAux(c, n, prev)
|
||||||
|
elif n[0].kind == nkNilLit and n.len == 2:
|
||||||
|
result = semTypeNode(c, n.sons[1], prev)
|
||||||
|
if result.skipTypes({tyGenericInst}).kind in NilableTypes+GenericTypes:
|
||||||
|
if tfNotNil in result.flags:
|
||||||
|
result = freshType(result, prev)
|
||||||
|
result.flags.excl(tfNotNil)
|
||||||
|
else:
|
||||||
|
localError(n.info, errGenerated, "invalid type")
|
||||||
elif n[0].kind notin nkIdentKinds:
|
elif n[0].kind notin nkIdentKinds:
|
||||||
result = semTypeExpr(c, n)
|
result = semTypeExpr(c, n)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -2584,11 +2584,7 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
|
|
||||||
when hasAlloc:
|
when hasAlloc:
|
||||||
var
|
var
|
||||||
strDesc: TNimType
|
strDesc = TNimType(size: sizeof(string), kind: tyString, flags: {ntfAcyclic})
|
||||||
|
|
||||||
strDesc.size = sizeof(string)
|
|
||||||
strDesc.kind = tyString
|
|
||||||
strDesc.flags = {ntfAcyclic}
|
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
include "system/ansi_c"
|
include "system/ansi_c"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue