Browse Source

Allow Delete() and Insert() to be used with generic types as arguments.

+ added test

git-svn-id: trunk@33897 -
svenbarth 9 years ago
parent
commit
aaff6d0b97
3 changed files with 34 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 6 0
      compiler/ninl.pas
  3. 27 0
      tests/tbs/tb0620.pp

+ 1 - 0
.gitattributes

@@ -10965,6 +10965,7 @@ tests/tbs/tb0616.pp svneol=native#text/pascal
 tests/tbs/tb0617.pp svneol=native#text/pascal
 tests/tbs/tb0617.pp svneol=native#text/pascal
 tests/tbs/tb0618.pp svneol=native#text/plain
 tests/tbs/tb0618.pp svneol=native#text/plain
 tests/tbs/tb0619.pp svneol=native#text/pascal
 tests/tbs/tb0619.pp svneol=native#text/pascal
+tests/tbs/tb0620.pp svneol=native#text/pascal
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tb613.pp svneol=native#text/plain
 tests/tbs/tb613.pp svneol=native#text/plain

+ 6 - 0
compiler/ninl.pas

@@ -4287,6 +4287,9 @@ implementation
            procname:='fpc_widestr_insert'
            procname:='fpc_widestr_insert'
          else if is_ansistring(second) then
          else if is_ansistring(second) then
            procname:='fpc_ansistr_insert'
            procname:='fpc_ansistr_insert'
+         else if second.typ=undefineddef then
+           { just pick one }
+           procname:='fpc_ansistr_insert'
          else
          else
            begin
            begin
              CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Insert');
              CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Insert');
@@ -4317,6 +4320,9 @@ implementation
            procname:='fpc_widestr_delete'
            procname:='fpc_widestr_delete'
          else if is_ansistring(first) then
          else if is_ansistring(first) then
            procname:='fpc_ansistr_delete'
            procname:='fpc_ansistr_delete'
+         else if first.typ=undefineddef then
+           { just pick one }
+           procname:='fpc_ansistr_delete'
          else
          else
            begin
            begin
              CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Delete');
              CGMessagePos1(fileinfo,parser_e_wrong_parameter_size,'Delete');

+ 27 - 0
tests/tbs/tb0620.pp

@@ -0,0 +1,27 @@
+{ %NORUN }
+
+program tb0620;
+
+type
+  generic TTest<T, S> = object
+    procedure Test(aArg: T; aArg2: S);
+  end;
+
+procedure TTest.Test(aArg: T; aArg2: S);
+begin
+  Delete(aArg, aArg2, 4);
+  Insert('Test', aArg, aArg2);
+  Writeln(aArg);
+end;
+
+type
+  TTestShortString = specialize TTest<ShortString, LongInt>;
+  TTestUnicodeString = specialize TTest<UnicodeString, LongInt>;
+
+var
+  tss: TTestShortString;
+  tus: TTestUnicodeString;
+begin
+  tss.Test('Hello World', 3);
+  tus.Test('Hello World', 4);
+end.