فهرست منبع

compiler: allow Assignment and Explicit operators for undefined defs (issue #0018567)

git-svn-id: trunk@16805 -
paul 14 سال پیش
والد
کامیت
9499692eeb
4فایلهای تغییر یافته به همراه32 افزوده شده و 10 حذف شده
  1. 1 0
      .gitattributes
  2. 12 9
      compiler/htypechk.pas
  3. 2 1
      compiler/pdecsub.pas
  4. 17 0
      tests/webtbs/tw18567

+ 1 - 0
.gitattributes

@@ -10957,6 +10957,7 @@ tests/webtbs/tw1850.pp svneol=native#text/plain
 tests/webtbs/tw1851.pp svneol=native#text/plain
 tests/webtbs/tw18512.pp svneol=native#text/pascal
 tests/webtbs/tw1856.pp svneol=native#text/plain
+tests/webtbs/tw18567 svneol=native#text/pascal
 tests/webtbs/tw1862.pp svneol=native#text/plain
 tests/webtbs/tw1863.pp svneol=native#text/plain
 tests/webtbs/tw1867.pp svneol=native#text/plain

+ 12 - 9
compiler/htypechk.pas

@@ -426,15 +426,18 @@ implementation
                   begin
                     eq:=compare_defs_ext(ld,pf.returndef,nothingn,conv,pd,[cdo_explicit]);
                     result:=
-                      (eq=te_incompatible) and
-                      { don't allow overloading assigning to custom shortstring
-                        types, because we also don't want to differentiate based
-                        on different shortstring types (e.g.,
-                        "operator :=(const v: variant) res: shorstring" also
-                        has to work for assigning a variant to a string[80])
-                      }
-                      (not is_shortstring(pf.returndef) or
-                       (tstringdef(pf.returndef).len=255));
+                      (eq=te_exact) or
+                      (
+                        (eq=te_incompatible) and
+                        { don't allow overloading assigning to custom shortstring
+                          types, because we also don't want to differentiate based
+                          on different shortstring types (e.g.,
+                          "operator :=(const v: variant) res: shorstring" also
+                          has to work for assigning a variant to a string[80])
+                        }
+                        (not is_shortstring(pf.returndef) or
+                         (tstringdef(pf.returndef).len=255))
+                      );
                   end
                 else
                 { enumerator is a special case too }

+ 2 - 1
compiler/pdecsub.pas

@@ -1463,7 +1463,8 @@ implementation
                          (torddef(pd.returndef).ordtype<>pasbool)) then
                         Message(parser_e_comparative_operator_return_boolean);
                      if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
-                        equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) then
+                        equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
+                        (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
                        message(parser_e_no_such_assignment)
                      else if not isoperatoracceptable(pd,optoken) then
                        Message(parser_e_overload_impossible);

+ 17 - 0
tests/webtbs/tw18567

@@ -0,0 +1,17 @@
+program tw18567;
+
+{$mode delphi}
+
+type
+  TSomeRecord <TData> = record
+    data: TData;
+    class operator Explicit(a: TData) : TSomeRecord;
+  end;
+
+  class operator TSomeRecord <TData>.Explicit (a: TData): TSomeRecord;
+  begin
+
+  end;
+
+begin
+end.