[swift-evolution] Code comments that check code validity.

Xiaodi Wu xiaodi.wu at gmail.com
Sat Jan 14 17:56:07 CST 2017


On Sat, Jan 14, 2017 at 5:50 PM, Amir Michail <a.michail at me.com> wrote:

>
> On Jan 14, 2017, at 6:46 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> On Sat, Jan 14, 2017 at 5:35 PM, Amir Michail <a.michail at me.com> wrote:
>
>>
>> > On Jan 14, 2017, at 6:28 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>> >
>> > This has been brought up on this list before. The conclusion of the
>> previous thread on this topic was that there is a way to do this:
>> >
>> > #if false
>> > // put your code here
>> > #endif
>> >
>>
>> This would not check the code for compilability within the surrounding
>> code. This requires more than a syntax check.
>
>
> I can't say I've ever needed that feature; could you share a concrete use
> case?
>
>
> Consider an array of levels for a game where some levels are commented out
> for possible future use. It would be nice to have such level entries
> continue to compile as the code elsewhere evolves and yet not be included
> in the executable.
>

```
enum Levels: Int {
  case foo = 1, bar, baz, boo
}

var levels: [Levels] = [
  .foo,
  .bar,
]

// disabled
_ = {
  levels += [
    .baz,
    .boo,
    // this won't compile if you add:
    // .nonExistent,
  ]
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170114/55affccd/attachment.html>


More information about the swift-evolution mailing list