Browse Source

* print an error for invalid type conversions

git-svn-id: branches/jvmbackend@18544 -
Jonas Maebe 14 years ago
parent
commit
54bb881a1b
1 changed files with 18 additions and 9 deletions
  1. 18 9
      compiler/jvm/njvmcnv.pas

+ 18 - 9
compiler/jvm/njvmcnv.pas

@@ -561,14 +561,18 @@ implementation
             exit;
           end;
         { int to float explicit type conversion: also use the bits }
-        if (convtype<>tc_int_2_real) and
-           (is_integer(left.resultdef) or
+        if (is_integer(left.resultdef) or
             (left.resultdef.typ=enumdef)) and
            (resultdef.typ=floatdef) then
           begin
-            if not check_only then
-              resnode:=int_real_explicit_typecast(tfloatdef(resultdef),'INTBITSTOFLOAT','LONGBITSTODOUBLE');
-            result:=true;
+            if (convtype<>tc_int_2_real) then
+              begin
+                if not check_only then
+                  resnode:=int_real_explicit_typecast(tfloatdef(resultdef),'INTBITSTOFLOAT','LONGBITSTODOUBLE');
+                result:=true;
+              end
+            else
+              result:=false;
             exit;
           end;
         { nothing special required when going between ordinals and enums }
@@ -579,10 +583,14 @@ implementation
             exit;
           end;
 
-{ifndef nounsupported}
-        result:=false;
-        exit;
-{endif}
+{$ifndef nounsupported}
+        if (left.resultdef.typ in [orddef,enumdef,setdef]) and
+           (resultdef.typ in [orddef,enumdef,setdef]) then
+          begin
+            result:=false;
+            exit;
+          end;
+{$endif}
 
         { Todo:
             * int to set and vice versa
@@ -594,6 +602,7 @@ implementation
               for Java)
         }
         { anything not explicitly handled is a problem }
+        result:=true;
         CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename);
       end;