parent
cb9d554ac9
commit
6e358e3187
4 changed files with 58 additions and 5 deletions
|
|
@ -218,13 +218,16 @@ proc semConv(c: PContext, n: PNode): PNode =
|
|||
proc semCast(c: PContext, n: PNode): PNode =
|
||||
## Semantically analyze a casting ("cast[type](param)")
|
||||
checkSonsLen(n, 2)
|
||||
let targetType = semTypeNode(c, n.sons[0], nil)
|
||||
let castedExpr = semExprWithType(c, n.sons[1])
|
||||
if tfHasMeta in targetType.flags:
|
||||
localError(n.sons[0].info, errCastToANonConcreteType, $targetType)
|
||||
if not isCastable(targetType, castedExpr.typ):
|
||||
localError(n.info, errExprCannotBeCastToX, $targetType)
|
||||
result = newNodeI(nkCast, n.info)
|
||||
result.typ = semTypeNode(c, n.sons[0], nil)
|
||||
result.typ = targetType
|
||||
addSon(result, copyTree(n.sons[0]))
|
||||
addSon(result, semExprWithType(c, n.sons[1]))
|
||||
if not isCastable(result.typ, result.sons[1].typ):
|
||||
localError(result.info, errExprCannotBeCastToX,
|
||||
typeToString(result.typ))
|
||||
addSon(result, castedExpr)
|
||||
|
||||
proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
|
||||
const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue