From 51326e94f38d72e89bc833c60e20df237502d811 Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 28 Jun 2021 20:35:33 +0000 Subject: [PATCH] * allow char constant to be used for const string parameters in generic specializations, resolves #39030 git-svn-id: trunk@49569 - --- .gitattributes | 1 + compiler/pgenutil.pas | 3 +++ tests/webtbs/tw39030.pp | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/webtbs/tw39030.pp diff --git a/.gitattributes b/.gitattributes index 051b70ff41..f40ede95c0 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index 1829ce335a..bd6e441658 100644 --- a/compiler/pgenutil.pas +++ b/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 diff --git a/tests/webtbs/tw39030.pp b/tests/webtbs/tw39030.pp new file mode 100644 index 0000000000..dbd104f24b --- /dev/null +++ b/tests/webtbs/tw39030.pp @@ -0,0 +1,22 @@ + +{$mode objfpc} +program gentest; + +generic function ConstString: 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.