Skip to content

Commit

Permalink
fixes #21027; cast expressions need a type
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Dec 6, 2022
1 parent 794bcc8 commit afadac3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ proc semCast(c: PContext, n: PNode): PNode =
let castedExpr = semExprWithType(c, n[1])
if castedExpr.kind == nkClosedSymChoice:
errorUseQualifier(c, n[1].info, castedExpr)
if targetType == nil:
localError(c.config, n.info, errExprXHasNoType %
renderTree(n, {renderNoComments}))
if tfHasMeta in targetType.flags:
localError(c.config, n[0].info, "cannot cast to a non concrete type: '$1'" % $targetType)
if not isCastable(c, targetType, castedExpr.typ, n.info):
Expand Down
5 changes: 5 additions & 0 deletions tests/types/t21027.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
discard """
errormsg: "expression 'cast(5)' has no type (or is ambiguous)"
"""
# bug #21027
let x: uint64 = cast(5)

0 comments on commit afadac3

Please sign in to comment.