* handle inc/dec/pred/succ correctly with type parameters, resolves #23299

git-svn-id: trunk@23248 -
This commit is contained in:
florian 2012-12-29 10:01:54 +00:00
parent f2ee6bcb77
commit d140c5b4ee
3 changed files with 37 additions and 4 deletions

1
.gitattributes vendored
View File

@ -13083,6 +13083,7 @@ tests/webtbs/tw23212.pp svneol=native#text/plain
tests/webtbs/tw2323.pp svneol=native#text/plain
tests/webtbs/tw23270.pp svneol=native#text/pascal
tests/webtbs/tw2328.pp svneol=native#text/plain
tests/webtbs/tw23299.pp svneol=native#text/pascal
tests/webtbs/tw2332.pp svneol=native#text/plain
tests/webtbs/tw23342.pp svneol=native#text/pascal
tests/webtbs/tw23436.pp svneol=native#text/plain

View File

@ -2698,15 +2698,15 @@ implementation
begin
set_varstate(left,vs_read,[vsf_must_be_valid]);
resultdef:=left.resultdef;
if not is_ordinal(resultdef) then
CGMessage(type_e_ordinal_expr_expected)
else
if is_ordinal(resultdef) or is_typeparam(resultdef) then
begin
if (resultdef.typ=enumdef) and
(tenumdef(resultdef).has_jumps) and
not(m_delphi in current_settings.modeswitches) then
CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
end;
end
else
CGMessage(type_e_ordinal_expr_expected)
end;
in_copy_x:
@ -2771,6 +2771,12 @@ implementation
CGMessagePos(tcallparanode(left).right.fileinfo,type_e_ordinal_expr_expected);
end;
end
{ generic type parameter? }
else if is_typeparam(left.resultdef) then
begin
result:=cnothingnode.create;
exit;
end
else
begin
hp:=self;

26
tests/webtbs/tw23299.pp Normal file
View File

@ -0,0 +1,26 @@
{$MODE DELPHI}
type
TSmallWrapper<TValue> = record
Value: TValue;
end;
TWrapper<T> = class
strict private
class var FSmallWrapper: TSmallWrapper<Integer>;
public
class procedure Z; static;
end;
class procedure TWrapper<T>.Z;
begin
FSmallWrapper.Value := 0;
Inc(FSmallWrapper.Value);
Dec(FSmallWrapper.Value);
FSmallWrapper.Value := Succ(FSmallWrapper.Value);
FSmallWrapper.Value := Pred(FSmallWrapper.Value);
end;
begin
TWrapper<Byte>.Z;
end.