fpc/tests/test/jvm/tenum2.pp
Jonas Maebe b0462d27cc * by default, no longer initialize enumeration fields of classes/objects
with the enum instance corresponding to ordinal 0 in JVM constructors,
    because a virtual method called by a parent constructor may already
    have assigned a different value (see tests/test/jvm/tenum2.pp). This
    will result in null pointer exceptions when using such fields without
    first explicitly assigning a value to them though.

    The old behaviour can be restored with the new -CTenumfieldinit command
    line parameter

git-svn-id: trunk@21736 -
2012-06-29 21:24:35 +00:00

35 lines
489 B
ObjectPascal

program tenum2;
{$mode delphi}
type
tenum2enum = (e_zero, e_one, e_two);
tenum2base = class abstract
constructor create;
procedure init; virtual; abstract;
end;
tenum2child = class(tenum2base)
fenum: tenum2enum;
procedure init; override;
end;
constructor tenum2base.create;
begin
init;
end;
procedure tenum2child.init;
begin
fenum:=e_one;
end;
var
c: tenum2child;
begin
c:=tenum2child.create;
if c.fenum<>e_one then
halt(1);
end.