braceless with statements

Stefan Koch uplink.coder at googlemail.com
Fri Nov 12 10:59:39 UTC 2021


On Friday, 12 November 2021 at 10:55:21 UTC, Stefan Koch wrote:
>
> And now this works:
> ```D
> struct S { int x; }
> int fn()
> {
>     S s;
>     with(s):
>     x = 12;
>     return x;
> }
> ```

Note: this will actually create an invisible scope from 
`with(x):` towards the end of the parent scope.
but it shouldn't affect anything you might do.

I just wanted to point out that using `x` in the example above 
will not work it it's done before the `with` statement.
only after and similarly the names introduced by `with` will go 
out of scope when the parent scope leaves.

```D
{
with(s):
  // only vaild for this scope
}
// s.x is not valid here anymore
```


More information about the Digitalmars-d mailing list