Преглед изворни кода

* throw a proper error if a contructur has a type parameter in delphi mode, resolves #37217

git-svn-id: trunk@48113 -
florian пре 4 година
родитељ
комит
7f775abb6d
6 измењених фајлова са 411 додато и 386 уклоњено
  1. 1 0
      .gitattributes
  2. 2 0
      compiler/msg/errore.msg
  3. 3 2
      compiler/msgidx.inc
  4. 335 335
      compiler/msgtxt.inc
  5. 58 49
      compiler/pdecsub.pas
  6. 12 0
      tests/webtbf/tw37217.pp

+ 1 - 0
.gitattributes

@@ -16689,6 +16689,7 @@ tests/webtbf/tw36720.pp svneol=native#text/pascal
 tests/webtbf/tw3680.pp svneol=native#text/plain
 tests/webtbf/tw36975.pp svneol=native#text/pascal
 tests/webtbf/tw3716.pp svneol=native#text/plain
+tests/webtbf/tw37217.pp svneol=native#text/pascal
 tests/webtbf/tw37272b.pp svneol=native#text/pascal
 tests/webtbf/tw37303.pp -text svneol=native#text/pascal
 tests/webtbf/tw3738.pp svneol=native#text/plain

+ 2 - 0
compiler/msg/errore.msg

@@ -1622,6 +1622,8 @@ parser_e_location_regpair_only_data=03358_E_Only data registers are supported fo
 % AmigaOS/MorphOS syscall specific: for 64bit register pairs, only data registers are supported
 parser_e_location_regpair_only_consecutive=03359_E_Only consecutive registers are supported for explicit location register pairs
 % MorphOS syscall specific: only consecutive (f.e.: d1-d2) registers are supported for 64bit register pairs
+parser_e_constructurs_cannot_take_type_parameters=03360_E_Constructors cannot take type parameters
+% The use of type parameters in constructors is not allowed.
 %
 % \end{description}
 %

+ 3 - 2
compiler/msgidx.inc

@@ -471,6 +471,7 @@ const
   parser_e_location_size_too_large=03357;
   parser_e_location_regpair_only_data=03358;
   parser_e_location_regpair_only_consecutive=03359;
+  parser_e_constructurs_cannot_take_type_parameters=03360;
   type_e_mismatch=04000;
   type_e_incompatible_types=04001;
   type_e_not_equal_types=04002;
@@ -1135,9 +1136,9 @@ const
   option_info=11024;
   option_help_pages=11025;
 
-  MsgTxtSize = 86847;
+  MsgTxtSize = 86896;
 
   MsgIdxMax : array[1..20] of longint=(
-    28,107,360,130,99,63,145,36,223,68,
+    28,107,361,130,99,63,145,36,223,68,
     63,20,30,1,1,1,1,1,1,1
   );

Разлика између датотеке није приказан због своје велике величине
+ 335 - 335
compiler/msgtxt.inc


+ 58 - 49
compiler/pdecsub.pas

@@ -1133,61 +1133,70 @@ implementation
 
         if assigned(genericparams) then
           begin
-            include(pd.defoptions,df_generic);
-            { push the parameter symtable so that constraint definitions are added
-              there and not in the owner symtable }
-            symtablestack.push(pd.parast);
-            { register the parameters }
-            for i:=0 to genericparams.count-1 do
+            if potype=potype_constructor then
               begin
-                 tsym(genericparams[i]).register_sym;
-                 if tsym(genericparams[i]).typ=typesym then
-                   tstoreddef(ttypesym(genericparams[i]).typedef).register_def;
-              end;
-            insert_generic_parameter_types(pd,nil,genericparams);
-            { the list is no longer required }
-            genericparams.free;
-            genericparams:=nil;
-            symtablestack.pop(pd.parast);
-            parse_generic:=true;
-            { also generate a dummy symbol if none exists already }
-            if assigned(astruct) then
-              dummysym:=tsym(astruct.symtable.find(spnongen))
+                Message(parser_e_constructurs_cannot_take_type_parameters);
+                genericparams.free;
+                genericparams:=nil;
+              end
             else
               begin
-                dummysym:=tsym(symtablestack.top.find(spnongen));
-                if not assigned(dummysym) and
-                    (symtablestack.top=current_module.localsymtable) and
-                    assigned(current_module.globalsymtable) then
-                  dummysym:=tsym(current_module.globalsymtable.find(spnongen));
-              end;
-            if not assigned(dummysym) then
-              begin
-                { overloading generic routines with non-generic types is not
-                  allowed, so we create a procsym as dummy }
-                dummysym:=cprocsym.create(orgspnongen);
+                include(pd.defoptions,df_generic);
+                { push the parameter symtable so that constraint definitions are added
+                  there and not in the owner symtable }
+                symtablestack.push(pd.parast);
+                { register the parameters }
+                for i:=0 to genericparams.count-1 do
+                  begin
+                     tsym(genericparams[i]).register_sym;
+                     if tsym(genericparams[i]).typ=typesym then
+                       tstoreddef(ttypesym(genericparams[i]).typedef).register_def;
+                  end;
+                insert_generic_parameter_types(pd,nil,genericparams);
+                { the list is no longer required }
+                genericparams.free;
+                genericparams:=nil;
+                symtablestack.pop(pd.parast);
+                parse_generic:=true;
+                { also generate a dummy symbol if none exists already }
                 if assigned(astruct) then
-                  astruct.symtable.insert(dummysym)
+                  dummysym:=tsym(astruct.symtable.find(spnongen))
                 else
-                  symtablestack.top.insert(dummysym);
-              end
-            else if (dummysym.typ<>procsym) and
-                (
-                  { show error only for the declaration, not also the implementation }
-                  not assigned(astruct) or
-                  (symtablestack.top.symtablelevel<>main_program_level)
-                ) then
-              Message1(sym_e_duplicate_id,dummysym.realname);
-            if not (sp_generic_dummy in dummysym.symoptions) then
-              begin
-                include(dummysym.symoptions,sp_generic_dummy);
-                add_generic_dummysym(dummysym);
+                  begin
+                    dummysym:=tsym(symtablestack.top.find(spnongen));
+                    if not assigned(dummysym) and
+                        (symtablestack.top=current_module.localsymtable) and
+                        assigned(current_module.globalsymtable) then
+                      dummysym:=tsym(current_module.globalsymtable.find(spnongen));
+                  end;
+                if not assigned(dummysym) then
+                  begin
+                    { overloading generic routines with non-generic types is not
+                      allowed, so we create a procsym as dummy }
+                    dummysym:=cprocsym.create(orgspnongen);
+                    if assigned(astruct) then
+                      astruct.symtable.insert(dummysym)
+                    else
+                      symtablestack.top.insert(dummysym);
+                  end
+                else if (dummysym.typ<>procsym) and
+                    (
+                      { show error only for the declaration, not also the implementation }
+                      not assigned(astruct) or
+                      (symtablestack.top.symtablelevel<>main_program_level)
+                    ) then
+                  Message1(sym_e_duplicate_id,dummysym.realname);
+                if not (sp_generic_dummy in dummysym.symoptions) then
+                  begin
+                    include(dummysym.symoptions,sp_generic_dummy);
+                    add_generic_dummysym(dummysym);
+                  end;
+                if dummysym.typ=procsym then
+                  tprocsym(dummysym).add_generic_overload(aprocsym);
+                { start token recorder for the declaration }
+                pd.init_genericdecl;
+                current_scanner.startrecordtokens(pd.genericdecltokenbuf);
               end;
-            if dummysym.typ=procsym then
-              tprocsym(dummysym).add_generic_overload(aprocsym);
-            { start token recorder for the declaration }
-            pd.init_genericdecl;
-            current_scanner.startrecordtokens(pd.genericdecltokenbuf);
           end
         else if assigned(genericdef) then
           insert_generic_parameter_types(pd,tstoreddef(genericdef),generictypelist);

+ 12 - 0
tests/webtbf/tw37217.pp

@@ -0,0 +1,12 @@
+{ %fail }
+{$mode delphi}
+type
+  TEagle = class
+    constructor Create<Y>();
+  end;
+
+constructor TEagle.Create<Y>();
+begin
+end;
+begin
+end.

Неке датотеке нису приказане због велике количине промена