fixes #9498, typeof is for everybody
This commit is contained in:
parent
8fbdac544b
commit
c844a9169c
2 changed files with 11 additions and 6 deletions
|
|
@ -201,7 +201,7 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
if targetType.kind == tyTypeDesc:
|
if targetType.kind == tyTypeDesc:
|
||||||
internalAssert c.config, targetType.len > 0
|
internalAssert c.config, targetType.len > 0
|
||||||
if targetType.base.kind == tyNone:
|
if targetType.base.kind == tyNone:
|
||||||
return semTypeOf(c, n[1])
|
return semTypeOf(c, n)
|
||||||
else:
|
else:
|
||||||
targetType = targetType.base
|
targetType = targetType.base
|
||||||
elif targetType.kind == tyStatic:
|
elif targetType.kind == tyStatic:
|
||||||
|
|
@ -1963,8 +1963,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
|
||||||
checkSonsLen(n, 2, c.config)
|
checkSonsLen(n, 2, c.config)
|
||||||
result = semAddr(c, n.sons[1], s.name.s == "unsafeAddr")
|
result = semAddr(c, n.sons[1], s.name.s == "unsafeAddr")
|
||||||
of mTypeOf:
|
of mTypeOf:
|
||||||
checkSonsLen(n, 2, c.config)
|
result = semTypeOf(c, n)
|
||||||
result = semTypeOf(c, n.sons[1])
|
|
||||||
#of mArrGet: result = semArrGet(c, n, flags)
|
#of mArrGet: result = semArrGet(c, n, flags)
|
||||||
#of mArrPut: result = semArrPut(c, n, flags)
|
#of mArrPut: result = semArrPut(c, n, flags)
|
||||||
#of mAsgn: result = semAsgnOpr(c, n)
|
#of mAsgn: result = semAsgnOpr(c, n)
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,15 @@ proc semAddr(c: PContext; n: PNode; isUnsafeAddr=false): PNode =
|
||||||
result.typ = makePtrType(c, x.typ)
|
result.typ = makePtrType(c, x.typ)
|
||||||
|
|
||||||
proc semTypeOf(c: PContext; n: PNode): PNode =
|
proc semTypeOf(c: PContext; n: PNode): PNode =
|
||||||
|
var m = BiggestInt 1 # typeOfIter
|
||||||
|
if n.len == 3:
|
||||||
|
let mode = semConstExpr(c, n[2])
|
||||||
|
if mode.kind != nkIntLit:
|
||||||
|
localError(c.config, n.info, "typeof: cannot evaluate 'mode' parameter at compile-time")
|
||||||
|
else:
|
||||||
|
m = mode.intVal
|
||||||
result = newNodeI(nkTypeOfExpr, n.info)
|
result = newNodeI(nkTypeOfExpr, n.info)
|
||||||
let typExpr = semExprWithType(c, n, {efInTypeof})
|
let typExpr = semExprWithType(c, n[1], if m == 1: {efInTypeof} else: {})
|
||||||
result.add typExpr
|
result.add typExpr
|
||||||
result.typ = makeTypeDesc(c, typExpr.typ)
|
result.typ = makeTypeDesc(c, typExpr.typ)
|
||||||
|
|
||||||
|
|
@ -320,8 +327,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
||||||
checkSonsLen(n, 2, c.config)
|
checkSonsLen(n, 2, c.config)
|
||||||
result = semAddr(c, n.sons[1], n[0].sym.name.s == "unsafeAddr")
|
result = semAddr(c, n.sons[1], n[0].sym.name.s == "unsafeAddr")
|
||||||
of mTypeOf:
|
of mTypeOf:
|
||||||
checkSonsLen(n, 2, c.config)
|
result = semTypeOf(c, n)
|
||||||
result = semTypeOf(c, n.sons[1])
|
|
||||||
of mSizeOf:
|
of mSizeOf:
|
||||||
# TODO there is no proper way to find out if a type cannot be queried for the size.
|
# TODO there is no proper way to find out if a type cannot be queried for the size.
|
||||||
let size = getSize(c.config, n[1].typ)
|
let size = getSize(c.config, n[1].typ)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue