Skip to content

Commit 4e00a7a

Browse files
committed
allow autofree in with var NAME : TYPE := EXPR do
Form D's `:= EXPR` branch now accepts the `autofree` keyword the same way Form C does. The class-instance check downstream rejects autofree on non-class targets, so aggregate-literal init (records/arrays) still errors as expected. Brings Form D to full feature parity with Form C on the autofree axis. ```pas with var a: TStringList := autofree TStringList.Create do a.Add('hello'); // a.Free called here ```
1 parent cd0326d commit 4e00a7a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

compiler/pstatmnt.pas

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,12 +1697,19 @@ twithshadowcand = class
16971697
lifetime_init := nil;
16981698
if try_to_consume(_ASSIGNMENT) then
16991699
begin
1700+
if current_scanner.token = _AUTOFREE then
1701+
begin
1702+
consume(_AUTOFREE);
1703+
lifetime_autofree := true;
1704+
lifetime_init := comp_expr([ef_accept_equal]);
1705+
do_typecheckpass(lifetime_init);
1706+
end
17001707
{ Aggregate literal init for record/array: reuse
17011708
typed-constant parser via a hidden static sym,
17021709
then copy it into the with-var. The plain
17031710
expression parser cannot handle (a, b, c) form. }
1704-
if (current_scanner.token = _LKLAMMER) and
1705-
((hdef.typ = arraydef) or (hdef.typ = recorddef)) then
1711+
else if (current_scanner.token = _LKLAMMER) and
1712+
((hdef.typ = arraydef) or (hdef.typ = recorddef)) then
17061713
begin
17071714
lifetime_tcsym := cstaticvarsym.create(
17081715
'$with_tc_' + lifetime_name, vs_const, hdef, []);

0 commit comments

Comments
 (0)