<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">How about keep it as is but if two cases have the same constant value generate an error/warning? I feel like if you're using non-constant expressions in case labels the programmer is responsible for dealing with overlapping cases.<br><br>It seems sensible to me to run the first matching case or default if none match. Running multiple cases seems counter intuitive.<br><br> Swift/t doesn't support expressions in switch anyway if that matters.</div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:hategan@mcs.anl.gov">Mihael Hategan</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">5/29/2015 6:46 PM</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:swift-devel@ci.uchicago.edu">Swift Devel</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">[Swift-devel] the switch statement</span><br><br></div>So I have some bad news. The switch statement is broken.<br><br>In most c-like languages, the case expressions are restricted to<br>literals. The reason is that it is the only way to reliably check for<br>conflicting cases. Allowing arbitrary expressions means that you can't<br>assert that the cases are non-overlapping at compile-time.<br><br>Swift allows expressions in cases. Furthermore, it implements the cases<br>as <br><br>if (expr == case1expr) {statements1}<br>else if (expr == case2expr) {statements2}<br>...<br><br>This means that when two cases have the same value, the second one will<br>be quietly ignored.<br><br>We have two options I think:<br><br>1. Remove the else. Run statements in all cases that have the right<br>value<br>2. Restrict case expressions to literals and check that there are no two<br>cases with the same value at compile-time.<br><br>Thoughts?<br><br>Mihael<br><br>_______________________________________________<br>Swift-devel mailing list<br>Swift-devel@ci.uchicago.edu<br>https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel<br></body></html>