diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index cb7b0ae4a87c..e5dd026e420f 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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): diff --git a/tests/types/t21027.nim b/tests/types/t21027.nim new file mode 100644 index 000000000000..7fd840d8cb85 --- /dev/null +++ b/tests/types/t21027.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "expression 'cast(5)' has no type (or is ambiguous)" +""" +# bug #21027 +let x: uint64 = cast(5)