* fixes #21027; cast expressions need a type * Apply suggestions from code review Thanks to @beef331
This commit is contained in:
parent
b2c7019006
commit
1564ae650f
2 changed files with 7 additions and 0 deletions
|
|
@ -394,6 +394,8 @@ proc semCast(c: PContext, n: PNode): PNode =
|
||||||
let castedExpr = semExprWithType(c, n[1])
|
let castedExpr = semExprWithType(c, n[1])
|
||||||
if castedExpr.kind == nkClosedSymChoice:
|
if castedExpr.kind == nkClosedSymChoice:
|
||||||
errorUseQualifier(c, n[1].info, castedExpr)
|
errorUseQualifier(c, n[1].info, castedExpr)
|
||||||
|
if targetType == nil:
|
||||||
|
localError(c.config, n.info, "Invalid usage of cast, cast requires a type to convert to, e.g., cast[int](0d).")
|
||||||
if tfHasMeta in targetType.flags:
|
if tfHasMeta in targetType.flags:
|
||||||
localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
|
localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
|
||||||
if not isCastable(c, targetType, castedExpr.typ, n.info):
|
if not isCastable(c, targetType, castedExpr.typ, n.info):
|
||||||
|
|
|
||||||
5
tests/types/t21027.nim
Normal file
5
tests/types/t21027.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "Invalid usage of cast, cast requires a type to convert to, e.g., cast[int](0d)."
|
||||||
|
"""
|
||||||
|
# bug #21027
|
||||||
|
let x: uint64 = cast(5)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue