Skip to content

Commit fb5b5f2

Browse files
committed
docs: Form D accepts autofree on the := EXPR form
1 parent 4e00a7a commit fb5b5f2

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

unleashed/docs/autofree.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ end;
195195
### Form D: inline-var declaration with explicit type
196196

197197
```pas
198-
with var NAME : TYPE [:= INIT] do BODY
198+
with var NAME : TYPE [:= [autofree] INIT] do BODY
199199
```
200200

201-
Declares a local of the given type, scoped to the with-body. Mirror of Form C but with an explicit type instead of type inference; the initializer is optional.
201+
Declares a local of the given type, scoped to the with-body. Mirror of Form C but with an explicit type instead of type inference; the initializer is optional, and accepts the same `autofree` modifier when present.
202202

203203
**Without initializer** - useful for stack-allocating a record local that the body fills in directly:
204204

@@ -234,7 +234,15 @@ with var q: record x, y: integer; end := (x: 5; y: 6) do
234234
writeln(x, ' ', y); // 5 6
235235
```
236236

237-
`autofree` is not accepted in Form D (the keyword belongs to the inferred-type Form C path).
237+
**With `autofree`** - explicit-type variant of Form C's auto-cleanup, useful when you want the type written in source rather than inferred:
238+
239+
```pas
240+
with var a: TStringList := autofree TStringList.Create do
241+
a.Add('hello');
242+
// a.Free called here
243+
```
244+
245+
`autofree` requires a class derived from `TObject`; aggregate-literal init on records/arrays still rejects it with `parser_e_autofree_requires_class`. Without an initializer there is no instance to free, so `autofree` only makes sense in the `:= EXPR` form.
238246

239247
### Form B: bind to an existing local
240248

0 commit comments

Comments
 (0)