diff options
-rw-r--r-- | compiler/semtypes.nim | 22 | ||||
-rw-r--r-- | lib/system.nim | 6 |
2 files changed, 19 insertions, 9 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 65cb9421b..bb59a9e75 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -135,13 +135,19 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = checkMinSonsLen(n, 1) var base = semTypeNode(c, n.lastSon, nil) result = newOrPrevType(kind, prev, c) + var isNilable = false # check every except the last is an object: for i in isCall .. n.len-2: - let region = semTypeNode(c, n[i], nil) - if region.skipTypes({tyGenericInst}).kind notin {tyError, tyObject}: - message n[i].info, errGenerated, "region needs to be an object type" - addSonSkipIntLit(result, region) + let ni = n[i] + if ni.kind == nkNilLit: + isNilable = true + 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) + #if not isNilable: result.flags.incl tfNotNil proc semVarType(c: PContext, n: PNode, prev: PType): PType = if sonsLen(n) == 1: @@ -1169,6 +1175,14 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = result = semTypeNode(c, b, prev) elif ident != nil and ident.id == ord(wDotDot): 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: result = semTypeExpr(c, n) else: diff --git a/lib/system.nim b/lib/system.nim index c5dd58c7b..2fb18fb51 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2584,11 +2584,7 @@ when not defined(JS): #and not defined(nimscript): when hasAlloc: var - strDesc: TNimType - - strDesc.size = sizeof(string) - strDesc.kind = tyString - strDesc.flags = {ntfAcyclic} + strDesc = TNimType(size: sizeof(string), kind: tyString, flags: {ntfAcyclic}) when not defined(nimscript): include "system/ansi_c" |