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

git-svn-id: trunk@49569 -
This commit is contained in:
florian 2021-06-28 20:35:33 +00:00
parent ce1f9cce01
commit 51326e94f3
3 changed files with 26 additions and 0 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/webtbs/tw39030.pp Normal file
View File

@ -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.