Skip to content

Commit 1564ae6

Browse files
authored
fixes #21027; cast expressions need a type (#21029)
* fixes #21027; cast expressions need a type * Apply suggestions from code review Thanks to @beef331
1 parent b2c7019 commit 1564ae6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/semexprs.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ proc semCast(c: PContext, n: PNode): PNode =
394394
let castedExpr = semExprWithType(c, n[1])
395395
if castedExpr.kind == nkClosedSymChoice:
396396
errorUseQualifier(c, n[1].info, castedExpr)
397+
if targetType == nil:
398+
localError(c.config, n.info, "Invalid usage of cast, cast requires a type to convert to, e.g., cast[int](0d).")
397399
if tfHasMeta in targetType.flags:
398400
localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
399401
if not isCastable(c, targetType, castedExpr.typ, n.info):

tests/types/t21027.nim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
discard """
2+
errormsg: "Invalid usage of cast, cast requires a type to convert to, e.g., cast[int](0d)."
3+
"""
4+
# bug #21027
5+
let x: uint64 = cast(5)

0 commit comments

Comments
 (0)