Replies: 1 comment
-
|
Feoramund escribió/skribis/wrote/scrit (2024-06-18T09:59:24-0700):
```odin
defer if a { /*...*/ }
defer {
if a { /*...*/ }
}
```
These two work the same at the moment, which is to say that the `if`
is only checked when the deferred statement is run,
That's the expected behaviour in both cases, which is clear: "A `defer`
statement defers the execution of a statement until the end of the scope
it is in. (…) You can defer an entire block too". Therefore you can
defer an `if` as well.
but the first reads as if the block should only be deferred if `a` is true.
You are right, but that impression may be caused by reading the code as
plain English.
Should `defer if a ...` raise a warning, or does this case need more documentation?
I think nothing is needed. In fact, the current [documentation of
`defer`](https://odin-lang.org/docs/overview/#defer-statement) already
includes an example of `defer if` as a deferred block.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The potential for a distinction between the following two blocks of code came up recently in #3781 (comment):
These two work the same at the moment, which is to say that the
ifis only checked when the deferred statement is run, but the first reads as if the block should only be deferred ifais true. Shoulddefer if a ...raise a warning, or does this case need more documentation?Beta Was this translation helpful? Give feedback.
All reactions