From f7c3c267945e45a5e81c376ad4296afcc60ef45b Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 14 Oct 2016 21:22:55 -0500 Subject: [PATCH] Report an error when trying to cast a void expression to a non-void type. --- Expression.pas | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Expression.pas b/Expression.pas index 983f6fd..b4b45ef 100644 --- a/Expression.pas +++ b/Expression.pas @@ -1931,13 +1931,20 @@ if (tp^.kind = scalarType) and (expressionType^.kind = scalarType) then begin rt := tp^.baseType; et := expressionType^.baseType; if rt <> et then - Gen2(pc_cnv, ord(et), ord(rt)); + if et <> cgVoid then + Gen2(pc_cnv, ord(et), ord(rt)) + else + Error(40); end {if} else if (tp^.kind = enumType) and (expressionType^.kind = scalarType) then begin - rt := cgWord; - et := Unary(expressionType^.baseType); - if rt <> et then - Gen2(pc_cnv, ord(et), ord(rt)); + if expressionType^.baseType <> cgVoid then begin + rt := cgWord; + et := Unary(expressionType^.baseType); + if rt <> et then + Gen2(pc_cnv, ord(et), ord(rt)); + end {if} + else + Error(40); end {if} else if (tp^.kind = scalarType) and (expressionType^.kind = enumType) then begin rt := Unary(tp^.baseType);