ソースを参照

* fix for Mantis #30534: don't consider all types with generic constraints as equal, but at least ensure that they have the same basetype (Note: this still needs a bit more improvement)
+ added test

git-svn-id: trunk@34526 -

svenbarth 9 年 前
コミット
0500c678e5
3 ファイル変更46 行追加14 行削除
  1. 1 0
      .gitattributes
  2. 27 14
      compiler/defcmp.pas
  3. 18 0
      tests/webtbs/tw30534.pp

+ 1 - 0
.gitattributes

@@ -15223,6 +15223,7 @@ tests/webtbs/tw30443.pp svneol=native#text/plain
 tests/webtbs/tw3045.pp svneol=native#text/plain
 tests/webtbs/tw3048.pp svneol=native#text/plain
 tests/webtbs/tw30522.pp svneol=native#text/plain
+tests/webtbs/tw30534.pp svneol=native#text/pascal
 tests/webtbs/tw30570.pp svneol=native#text/plain
 tests/webtbs/tw30572.pp svneol=native#text/plain
 tests/webtbs/tw3063.pp svneol=native#text/plain

+ 27 - 14
compiler/defcmp.pas

@@ -275,20 +275,33 @@ implementation
            end
          else
            begin
-             { undefined defs or defs with generic constraints are
-               considered equal to everything }
-             if (
-                   (def_from.typ=undefineddef) or
-                   assigned(tstoreddef(def_from).genconstraintdata)
-                 ) or (
-                   (def_to.typ=undefineddef) or
-                   assigned(tstoreddef(def_to).genconstraintdata)
-                 ) then
-              begin
-                doconv:=tc_equal;
-                compare_defs_ext:=te_exact;
-                exit;
-              end;
+             { undefined defs are considered equal to everything }
+             if (def_from.typ=undefineddef) or
+                 (def_to.typ=undefineddef) then
+               begin
+                 doconv:=tc_equal;
+                 compare_defs_ext:=te_exact;
+                 exit;
+               end;
+
+             { either type has constraints }
+             if assigned(tstoreddef(def_from).genconstraintdata) or
+                 assigned(tstoreddef(def_to).genconstraintdata) then
+               begin
+                 if def_from.typ<>def_to.typ then
+                   begin
+                     { not compatible anyway }
+                     doconv:=tc_not_possible;
+                     compare_defs_ext:=te_incompatible;
+                     exit;
+                   end;
+
+                 { one is definitely a constraint, for the other we don't
+                   care right now }
+                 doconv:=tc_equal;
+                 compare_defs_ext:=te_exact;
+                 exit;
+               end;
            end;
 
          { two specializations are considered equal if they specialize the same

+ 18 - 0
tests/webtbs/tw30534.pp

@@ -0,0 +1,18 @@
+{ %NORUN }
+
+{$MODE DELPHI}
+
+type
+  TSmartPtr<T: class> = record
+    class operator Implicit(aValue: T): TSmartPtr<T>;
+  end;
+
+class operator TSmartPtr<T>.Implicit(aValue: T): TSmartPtr<T>;
+begin
+end;
+
+var
+  sp: TSmartPtr<TObject>;
+begin
+  sp := nil;
+end.