소스 검색

compiler:
- don't allow operator enumerator with non object/class/interface result type
- add some test from Alexander S. Klenin
(issue #0014990)

git-svn-id: trunk@14043 -

paul 15 년 전
부모
커밋
5f7bc2d3b5
6개의 변경된 파일28개의 추가작업 그리고 11개의 파일을 삭제
  1. 2 0
      .gitattributes
  2. 1 9
      compiler/htypechk.pas
  3. 1 1
      compiler/symdef.pas
  4. 2 1
      compiler/symsym.pas
  5. 8 0
      tests/test/tforin20.pp
  6. 14 0
      tests/test/tforin21.pp

+ 2 - 0
.gitattributes

@@ -8238,6 +8238,8 @@ tests/test/tforin17.pp svneol=native#text/pascal
 tests/test/tforin18.pp svneol=native#text/pascal
 tests/test/tforin19.pp svneol=native#text/pascal
 tests/test/tforin2.pp svneol=native#text/pascal
+tests/test/tforin20.pp svneol=native#text/pascal
+tests/test/tforin21.pp svneol=native#text/pascal
 tests/test/tforin3.pp svneol=native#text/pascal
 tests/test/tforin4.pp svneol=native#text/pascal
 tests/test/tforin5.pp svneol=native#text/pascal

+ 1 - 9
compiler/htypechk.pas

@@ -425,16 +425,8 @@ implementation
                 { enumerator is a special case too }
                 if optoken=_OP_ENUMERATOR then
                   begin
-                    //eq:=check_that_return_type_is_ok_for_enumerator;
                     result:=
-                      { 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));
+                      is_class_or_interface_or_object(pf.returndef);
                   end
                 else
                   begin

+ 1 - 1
compiler/symdef.pas

@@ -4286,7 +4286,7 @@ implementation
                 begin
                   pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
                   if (pd.proctypeoption = potype_function) and
-                     (pd.returndef.typ = objectdef) and
+                     is_class_or_interface_or_object(pd.returndef) and
                      (pd.visibility >= vis_public) then
                   begin
                     result:=pd;

+ 2 - 1
compiler/symsym.pas

@@ -813,7 +813,8 @@ implementation
                 inc(realparamcount);
             if (paraidx<pd.paras.count) and
                assigned(pd.paras[paraidx]) and
-               (realparamcount = 1) then
+               (realparamcount = 1) and
+               is_class_or_interface_or_object(pd.returndef)  then
               begin
                 eq:=compare_defs_ext(typedef,tparavarsym(pd.paras[paraidx]).vardef,nothingn,convtyp,hpd,[]);
 

+ 8 - 0
tests/test/tforin20.pp

@@ -0,0 +1,8 @@
+{$mode objfpc}
+{$apptype console}
+type T = (a1, b1=5);
+var
+  ch: T;
+begin
+  for ch in T do Writeln(ch);
+end.

+ 14 - 0
tests/test/tforin21.pp

@@ -0,0 +1,14 @@
+{ %FAIL}
+{$mode objfpc}
+{$apptype console}
+
+operator enumerator(a: Integer): Integer;
+begin
+  Result := 0;
+end;
+
+var
+  i: Integer;
+begin
+  for i in 1 do Writeln(i);
+end.