Allow typeof(nil) as a return type
This commit is contained in:
parent
9ae0dd611f
commit
efe1bed82e
4 changed files with 8 additions and 2 deletions
|
|
@ -155,6 +155,7 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
|
||||||
of tyNone, tyTyped: result = ctVoid
|
of tyNone, tyTyped: result = ctVoid
|
||||||
of tyBool: result = ctBool
|
of tyBool: result = ctBool
|
||||||
of tyChar: result = ctChar
|
of tyChar: result = ctChar
|
||||||
|
of tyNil: result = ctPtr
|
||||||
of tySet: result = mapSetType(conf, typ)
|
of tySet: result = mapSetType(conf, typ)
|
||||||
of tyOpenArray, tyArray, tyVarargs, tyUncheckedArray: result = ctArray
|
of tyOpenArray, tyArray, tyVarargs, tyUncheckedArray: result = ctArray
|
||||||
of tyObject, tyTuple: result = ctStruct
|
of tyObject, tyTuple: result = ctStruct
|
||||||
|
|
|
||||||
|
|
@ -1600,6 +1600,8 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
|
||||||
result = putToSeq("{}", indirect)
|
result = putToSeq("{}", indirect)
|
||||||
of tyBool:
|
of tyBool:
|
||||||
result = putToSeq("false", indirect)
|
result = putToSeq("false", indirect)
|
||||||
|
of tyNil:
|
||||||
|
result = putToSeq("null", indirect)
|
||||||
of tyArray:
|
of tyArray:
|
||||||
let length = toInt(lengthOrd(p.config, t))
|
let length = toInt(lengthOrd(p.config, t))
|
||||||
let e = elemType(t)
|
let e = elemType(t)
|
||||||
|
|
|
||||||
|
|
@ -1310,7 +1310,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||||
tyNone, tyForward, tyFromExpr:
|
tyNone, tyForward, tyFromExpr:
|
||||||
result = t
|
result = t
|
||||||
of tyNil:
|
of tyNil:
|
||||||
if kind != skConst and kind != skParam: result = t
|
if kind != skConst and kind != skParam and kind != skResult: result = t
|
||||||
of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, tyPointer:
|
of tyString, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCString, tyPointer:
|
||||||
result = nil
|
result = nil
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,6 @@ f3(typeof(nil))
|
||||||
|
|
||||||
proc f4[T](_: T) = discard
|
proc f4[T](_: T) = discard
|
||||||
f4(nil)
|
f4(nil)
|
||||||
|
|
||||||
|
proc f5(): typeof(nil) = nil
|
||||||
|
discard f5()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue