pdecl.pas, readconstant: If we are parsing a constant declaration in a generic and we encounter an intrinsic then this intrinsic is left as is (thus the node p returned by comp_expr will be a inlinen instead of an expected ordconstn, stringconstn, etc.). Nevertheless we need to create a symbol for the constant (which isn't done otherwise). In the case of SizeOf a constant "0" will be created. This fixes Mantis #21593.

git-svn-id: trunk@21498 -
This commit is contained in:
svenbarth 2012-06-06 15:00:28 +00:00
parent 7332a0f801
commit aa0f1bdf26
5 changed files with 81 additions and 2 deletions

3
.gitattributes vendored
View File

@ -12603,6 +12603,9 @@ tests/webtbs/tw2159.pp svneol=native#text/plain
tests/webtbs/tw21592.pp svneol=native#text/pascal
tests/webtbs/tw21592b.pp svneol=native#text/pascal
tests/webtbs/tw21593.pp svneol=native#text/pascal
tests/webtbs/tw21593a.pp svneol=native#text/pascal
tests/webtbs/tw21593b.pp svneol=native#text/pascal
tests/webtbs/tw21593c.pp svneol=native#text/pascal
tests/webtbs/tw2163.pp svneol=native#text/plain
tests/webtbs/tw21654.pp svneol=native#text/pascal
tests/webtbs/tw21674.pp svneol=native#text/pascal

View File

@ -153,9 +153,27 @@ implementation
else
Message(parser_e_illegal_expression);
end;
inlinen:
begin
{ this situation only happens if a intrinsic is parsed that has a
generic type as its argument. As we don't know certain
information about the final type yet, we need to use safe
values (mostly 0) }
if not parse_generic then
Message(parser_e_illegal_expression);
case tinlinenode(p).inlinenumber of
in_sizeof_x,
in_bitsizeof_x:
begin
hp:=tconstsym.create_ord(orgname,constord,0,p.resultdef);
end;
{ add other cases here if necessary }
else
Message(parser_e_illegal_expression);
end;
end;
else
if not(parse_generic) then
Message(parser_e_illegal_expression);
Message(parser_e_illegal_expression);
end;
current_tokenpos:=storetokenpos;
p.free;

19
tests/webtbs/tw21593a.pp Normal file
View File

@ -0,0 +1,19 @@
program tw21593a;
{$MODE DELPHI}
type
TWrapper<T> = record
class procedure Test; static;
end;
class procedure TWrapper<T>.Test;
const
Size = SizeOf(T); { Error: Illegal expression }
begin
Writeln(Size);
end;
begin
TWrapper<Byte>.Test;
end.

20
tests/webtbs/tw21593b.pp Normal file
View File

@ -0,0 +1,20 @@
program tw21593b;
{$MODE DELPHI}
type
TWrapper<T> = record
strict private
const Size = SizeOf(T); { Error: Illegal expression }
public
class procedure Test; static;
end;
class procedure TWrapper<T>.Test;
begin
Writeln(Size);
end;
begin
TWrapper<Byte>.Test;
end.

19
tests/webtbs/tw21593c.pp Normal file
View File

@ -0,0 +1,19 @@
program tw21593c;
{$MODE DELPHI}
type
TWrapper<T> = record
class procedure Test; static;
end;
class procedure TWrapper<T>.Test;
var
size: SizeInt = SizeOf(T); { Error: Illegal expression }
begin
Writeln(size);
end;
begin
TWrapper<Byte>.Test;
end.