浏览代码

* do not allow constraints in headers of procedure implementations in delphi mode, resolves #36584
* better error message if a constraint is found at a wrong location

git-svn-id: trunk@44174 -

florian 5 年之前
父节点
当前提交
b7afb2431c
共有 7 个文件被更改,包括 342 次插入312 次删除
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 309 306
      compiler/msgtxt.inc
  5. 1 1
      compiler/pdecsub.pas
  6. 1 2
      compiler/pgenutil.pas
  7. 23 0
      tests/webtbf/tw36584.pp

+ 1 - 0
.gitattributes

@@ -16226,6 +16226,7 @@ tests/webtbf/tw36397.pp -text svneol=native#text/pascal
 tests/webtbf/tw3643.pp svneol=native#text/plain
 tests/webtbf/tw3644.pp svneol=native#text/plain
 tests/webtbf/tw36554.pp svneol=native#text/pascal
+tests/webtbf/tw36584.pp svneol=native#text/pascal
 tests/webtbf/tw3662.pp svneol=native#text/plain
 tests/webtbf/tw36631a.pp svneol=native#text/pascal
 tests/webtbf/tw36631b.pp svneol=native#text/pascal

+ 4 - 1
compiler/msg/errore.msg

@@ -436,7 +436,7 @@ scan_n_changecputype=02105_N_Changed CPU type to be consistent with specified co
 #
 # Parser
 #
-# 03354 is the last used one
+# 03355 is the last used one
 #
 % \section{Parser messages}
 % This section lists all parser messages. The parser takes care of the
@@ -1609,6 +1609,9 @@ parser_w_enumeration_out_of_range=03353_W_Enumeration symbols can only have valu
 parser_e_method_for_type_in_other_unit=03354_E_Implementing a method for type "$1" declared in another unit
 % This error occurs if one tries to define a method for a type that is originally declared
 % in a different unit.
+parser_e_generic_constraints_not_allowed_here=03355_E_Generic constraint not allowed here
+% At the current location specifying a constraint is not allowed. For example
+% in delphi mode, a constraint might not be specified in the header of the implementation.
 %
 % \end{description}
 %

+ 3 - 2
compiler/msgidx.inc

@@ -465,6 +465,7 @@ const
   parser_e_enumeration_out_of_range=03352;
   parser_w_enumeration_out_of_range=03353;
   parser_e_method_for_type_in_other_unit=03354;
+  parser_e_generic_constraints_not_allowed_here=03355;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -1122,9 +1123,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 84622;
+  MsgTxtSize = 84666;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,106,355,127,99,63,143,35,223,68,
+    28,106,356,127,99,63,143,35,223,68,
     62,20,30,1,1,1,1,1,1,1
   );

文件差异内容过多而无法显示
+ 309 - 306
compiler/msgtxt.inc


+ 1 - 1
compiler/pdecsub.pas

@@ -664,7 +664,7 @@ implementation
                       message(type_e_type_id_expected)
                     else
                       begin
-                        genericparams:=parse_generic_parameters(true);
+                        genericparams:=parse_generic_parameters(not(m_delphi in current_settings.modeswitches) or parse_only);
                         if not assigned(genericparams) then
                           internalerror(2015061201);
                         if genericparams.count=0 then

+ 1 - 2
compiler/pgenutil.pas

@@ -1186,8 +1186,7 @@ uses
           if try_to_consume(_COLON) then
             begin
               if not allowconstraints then
-                { TODO }
-                Message(parser_e_illegal_expression{ parser_e_generic_constraints_not_allowed_here});
+                Message(parser_e_generic_constraints_not_allowed_here);
               { construct a name which can be used for a type specification }
               constraintdata:=tgenericconstraintdata.create;
               defname:='';

+ 23 - 0
tests/webtbf/tw36584.pp

@@ -0,0 +1,23 @@
+{ %fail }
+{$mode delphi}
+program test;
+
+type
+ TFooA = class
+ end;
+
+type
+ TFooB = class
+ end;
+
+type
+ TList<T: TFooA> = class
+   procedure Foo;
+ end;
+
+procedure TList<T: TFooB>.Foo;
+begin
+end;
+
+begin
+end.

部分文件因为文件数量过多而无法显示