瀏覽代碼

compiler: require at least one argument of class operator to be of type of structure where this operator is declared

git-svn-id: trunk@16644 -
paul 14 年之前
父節點
當前提交
51a9d3280c
共有 6 個文件被更改,包括 344 次插入298 次删除
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 297 294
      compiler/msgtxt.inc
  5. 15 1
      compiler/pdecsub.pas
  6. 24 0
      tests/test/terecs7.pp

+ 1 - 0
.gitattributes

@@ -9329,6 +9329,7 @@ tests/test/terecs3.pp svneol=native#text/pascal
 tests/test/terecs4.pp svneol=native#text/pascal
 tests/test/terecs5.pp svneol=native#text/pascal
 tests/test/terecs6.pp svneol=native#text/pascal
+tests/test/terecs7.pp svneol=native#text/pascal
 tests/test/terecs_u1.pp svneol=native#text/pascal
 tests/test/testcmem.pp svneol=native#text/plain
 tests/test/testda1.pp svneol=native#text/plain

+ 4 - 1
compiler/msg/errore.msg

@@ -368,7 +368,7 @@ scanner_w_illegal_warn_identifier=02087_W_Illegal identifier "$1" for $WARN dire
 #
 # Parser
 #
-# 03302 is the last used one
+# 03303 is the last used one
 #
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
@@ -1360,6 +1360,9 @@ parser_e_class_methods_only_static_in_records=03301_E_Class methods must be stat
 parser_e_no_constructor_in_records=03302_E_Constructors aren't allowed in records
 % Constructor declarations aren't allowed in records.
 % \end{description}
+parser_e_at_least_one_argument_must_be_of_type=03303_E_At least one argument must be of type "$1"
+% It is required that at least one argument be of type of structure where this method is defined.
+% For example class operators must contain at least one argument of the structure where they are defined.
 #
 # Type Checking
 #

+ 3 - 2
compiler/msgidx.inc

@@ -391,6 +391,7 @@ const
   parser_e_no_destructor_in_records=03300;
   parser_e_class_methods_only_static_in_records=03301;
   parser_e_no_constructor_in_records=03302;
+  parser_e_at_least_one_argument_must_be_of_type=03303;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -876,9 +877,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 58219;
+  MsgTxtSize = 58270;
 
   MsgIdxMax : array[1..20] of longint=(
-    24,88,303,97,82,54,111,22,202,63,
+    24,88,304,97,82,54,111,22,202,63,
     49,20,1,1,1,1,1,1,1,1
   );

File diff suppressed because it is too large
+ 297 - 294
compiler/msgtxt.inc


+ 15 - 1
compiler/pdecsub.pas

@@ -1182,8 +1182,10 @@ implementation
 
     function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef):tprocdef;
       var
-        pd : tprocdef;
+        pd: tprocdef;
         locationstr: string;
+        i: integer;
+        found: boolean;
 
         procedure read_returndef(pd: tprocdef);
           var
@@ -1377,6 +1379,18 @@ implementation
                   else
                    begin
                      read_returndef(pd);
+                     if (po_classmethod in pd.procoptions) then
+                       begin
+                         found:=false;
+                         for i := 0 to pd.parast.SymList.Count - 1 do
+                           if tparavarsym(pd.parast.SymList[0]).vardef=pd.struct then
+                             begin
+                               found:=true;
+                               break;
+                             end;
+                         if not found then
+                           Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName);
+                       end;
                      if (optoken in [_EQ,_NE,_GT,_LT,_GTE,_LTE,_OP_IN]) and
                         ((pd.returndef.typ<>orddef) or
                          (torddef(pd.returndef).ordtype<>pasbool)) then

+ 24 - 0
tests/test/terecs7.pp

@@ -0,0 +1,24 @@
+{ %fail }
+program terecs7;
+
+{$MODE DELPHI}
+{$APPTYPE CONSOLE}
+
+type
+  TBar = record
+  end;
+
+  TFoo = record
+    class operator GreaterThan(i, j: TBar): Boolean;
+  end;
+
+{ TFoo }
+
+class operator TFoo.GreaterThan(i, j: TBar): Boolean;
+begin
+
+end;
+
+begin
+end.
+

Some files were not shown because too many files changed in this diff