61
Ideas / Re: Switch proposal
« on: November 28, 2018, 12:45:15 PM »
Also to discuss, should we automatically open a scope or not. If we automatically open a scope in cases, we prevent this nice code:
This since the implicit scope would trigger the defer when passing into the READ_WITHOUT_LOCK (I assume current syntax, so this is fallthrough automatically)
Of course, we could make | / fallthrough mean that scope is shared. That would make this execute correctly (new syntax):
Code: [Select]
switch (state) {
case READ_WITH_LOCK:;
LOCK *lock = acquire_lock();
defer lock.release();
case READ_WITHOUT_LOCK:
read_from_resource();
break;
case ...
}
This since the implicit scope would trigger the defer when passing into the READ_WITHOUT_LOCK (I assume current syntax, so this is fallthrough automatically)
Of course, we could make | / fallthrough mean that scope is shared. That would make this execute correctly (new syntax):
Code: [Select]
switch (state) {
case READ_WITH_LOCK:;
LOCK *lock = acquire_lock();
defer lock.release();
| case READ_WITHOUT_LOCK:
read_from_resource();
case ...
}