فهرست منبع

* when checking for an existing operator overload for the assignment operator, check for the correct variant (explicit or not) matching the overload
+ added tests

git-svn-id: trunk@44746 -

svenbarth 5 سال پیش
والد
کامیت
de35356a4d
4فایلهای تغییر یافته به همراه39 افزوده شده و 1 حذف شده
  1. 2 0
      .gitattributes
  2. 5 1
      compiler/htypechk.pas
  3. 16 0
      tests/test/toperator89.pp
  4. 16 0
      tests/test/toperator90.pp

+ 2 - 0
.gitattributes

@@ -15263,7 +15263,9 @@ tests/test/toperator85.pp svneol=native#text/pascal
 tests/test/toperator86.pp svneol=native#text/pascal
 tests/test/toperator87.pp svneol=native#text/pascal
 tests/test/toperator88.pp svneol=native#text/pascal
+tests/test/toperator89.pp svneol=native#text/pascal
 tests/test/toperator9.pp svneol=native#text/pascal
+tests/test/toperator90.pp svneol=native#text/pascal
 tests/test/toperatorerror.pp svneol=native#text/plain
 tests/test/tover1.pp svneol=native#text/plain
 tests/test/tover2.pp svneol=native#text/plain

+ 5 - 1
compiler/htypechk.pas

@@ -618,6 +618,7 @@ implementation
         i : longint;
         eq : tequaltype;
         conv : tconverttype;
+        cdo : tcompare_defs_options;
         pd : tprocdef;
         oldcount,
         count: longint;
@@ -663,7 +664,10 @@ implementation
                 { assignment is a special case }
                 if optoken in [_ASSIGNMENT,_OP_EXPLICIT] then
                   begin
-                    eq:=compare_defs_ext(ld,pf.returndef,nothingn,conv,pd,[cdo_explicit]);
+                    cdo:=[];
+                    if optoken=_OP_EXPLICIT then
+                      include(cdo,cdo_explicit);
+                    eq:=compare_defs_ext(ld,pf.returndef,nothingn,conv,pd,cdo);
                     result:=
                       (eq=te_exact) or
                       (

+ 16 - 0
tests/test/toperator89.pp

@@ -0,0 +1,16 @@
+{ %NORUN }
+
+program toperator89;
+
+{$mode objfpc}{$H+}
+
+{ overloading the implicit assignment is allowed }
+
+operator := (aArg: LongInt): Boolean;
+begin
+  Result := aArg <> 0;
+end;
+
+begin
+
+end.

+ 16 - 0
tests/test/toperator90.pp

@@ -0,0 +1,16 @@
+{ %FAIL }
+
+program toperator90;
+
+{$mode objfpc}{$H+}
+
+{ overloading the explicit assignment is NOT allowed }
+
+operator Explicit (aArg: LongInt): Boolean;
+begin
+  Result := aArg <> 0;
+end;
+
+begin
+
+end.