Просмотр исходного кода

* allow exlicit type conversions from class/interface to enums in Delphi
mode (mantis #11859)
* cleaned up some superfluous "eq=te_incompatible" checks (probably from
copy/pasting conditions from elsewhere)

git-svn-id: trunk@13050 -

Jonas Maebe 16 лет назад
Родитель
Сommit
5b08047d1c
3 измененных файлов с 35 добавлено и 6 удалено
  1. 1 0
      .gitattributes
  2. 14 6
      compiler/defcmp.pas
  3. 20 0
      tests/webtbs/tw11859.pp

+ 1 - 0
.gitattributes

@@ -8746,6 +8746,7 @@ tests/webtbs/tw11846b.pp svneol=native#text/plain
 tests/webtbs/tw11848.pp svneol=native#text/plain
 tests/webtbs/tw11849.pp svneol=native#text/plain
 tests/webtbs/tw11852.pp svneol=native#text/plain
+tests/webtbs/tw11859.pp svneol=native#text/plain
 tests/webtbs/tw11861.pp svneol=native#text/plain
 tests/webtbs/tw11862.pp svneol=native#text/plain
 tests/webtbs/tw11896.pp svneol=native#text/plain

+ 14 - 6
compiler/defcmp.pas

@@ -614,8 +614,18 @@ implementation
                    begin
                      { ugly, but delphi allows it }
                      if (cdo_explicit in cdoptions) and
-                       (m_delphi in current_settings.modeswitches) and
-                       (eq=te_incompatible) then
+                       (m_delphi in current_settings.modeswitches) then
+                       begin
+                         doconv:=tc_int_2_int;
+                         eq:=te_convert_l1;
+                       end;
+                   end;
+                 objectdef:
+                   begin
+                     { ugly, but delphi allows it }
+                     if (m_delphi in current_settings.modeswitches) and
+                        is_class_or_interface_or_dispinterface(def_from) and
+                        (cdo_explicit in cdoptions) then
                        begin
                          doconv:=tc_int_2_int;
                          eq:=te_convert_l1;
@@ -962,8 +972,7 @@ implementation
                      { allow explicit typecasts from enums to pointer.
                        Support for delphi compatibility
                      }
-                     if (eq=te_incompatible) and
-                        (((cdo_explicit in cdoptions) and
+                     if (((cdo_explicit in cdoptions) and
                           (m_delphi in current_settings.modeswitches)
                           ) or
                          (cdo_internal in cdoptions)
@@ -1263,8 +1272,7 @@ implementation
                        eq:=te_convert_l2;
                      end
                    { ugly, but delphi allows it }
-                   else if (eq=te_incompatible) and
-                     (def_from.typ in [orddef,enumdef]) and
+                   else if (def_from.typ in [orddef,enumdef]) and
                      (m_delphi in current_settings.modeswitches) and
                      (cdo_explicit in cdoptions) then
                      begin

+ 20 - 0
tests/webtbs/tw11859.pp

@@ -0,0 +1,20 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif}
+
+{$z4}
+type
+  tenum = (ea,eb,ec);
+
+var
+  c1, c2: tobject;
+  e: tenum;
+begin
+{$r-}
+  c1:=tobject(pointer(12345));
+  e:=tenum(c1);
+  c2:=tobject(e);
+  if (c1<>c2) then
+    halt(1);
+end.
+