Explorar el Código

* allow char constant to be used for const string parameters in generic specializations, resolves #39030

git-svn-id: trunk@49569 -
florian hace 4 años
padre
commit
51326e94f3
Se han modificado 3 ficheros con 26 adiciones y 0 borrados
  1. 1 0
      .gitattributes
  2. 3 0
      compiler/pgenutil.pas
  3. 22 0
      tests/webtbs/tw39030.pp

+ 1 - 0
.gitattributes

@@ -18880,6 +18880,7 @@ tests/webtbs/tw38940.pp svneol=native#text/pascal
 tests/webtbs/tw3898.pp svneol=native#text/plain
 tests/webtbs/tw3899.pp svneol=native#text/plain
 tests/webtbs/tw3900.pp svneol=native#text/plain
+tests/webtbs/tw39030.pp svneol=native#text/pascal
 tests/webtbs/tw3913.pp svneol=native#text/plain
 tests/webtbs/tw3930.pp svneol=native#text/plain
 tests/webtbs/tw3931a.pp svneol=native#text/plain

+ 3 - 0
compiler/pgenutil.pas

@@ -116,6 +116,9 @@ uses
         { integer ords are compatible with float }
         else if (param1.typ=orddef) and is_integer(param1) and (param2.typ=floatdef) then
           result:=true
+        { chars are compatible with stringdef }
+        else if (param1.typ=orddef) and is_char(param1) and (param2.typ=stringdef) then
+          result:=true
         { undefined def is compatible with all types }
         else if param2.typ=undefineddef then
           result:=true

+ 22 - 0
tests/webtbs/tw39030.pp

@@ -0,0 +1,22 @@
+
+{$mode objfpc}
+program gentest;
+
+generic function ConstString<const P,Q,S: string>: PChar;
+var
+  size: Integer;
+begin
+  Size := SizeOf(P) + SizeOf(Q) + SizeOf(S);
+  writeln(Size);
+
+  Result := P+Q+S;
+end;
+
+var
+  s: PChar;
+begin
+  s := specialize ConstString<'Hello', ' world', '!'>; // error gentest.lpr(16,50) Error: Incompatible types: got "Char" expected "AnsiString"
+  if s<>'Hello world!' then
+    halt(1);
+  writeln(s);
+end.