DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.56k stars 33 forks source link

Semicolon causes implicit fallthrough in switch #1602

Closed bbrk24 closed 2 days ago

bbrk24 commented 1 week ago

When the switch is the last statement in the function, each branch gets an implicit return. If you use ; to suppress the return, there is no break to replace it, so the branch falls through:

->
  switch foo
    when 0
      // implicit `break`
    else
      console.log 'Not zero'
  switch bar
    when 0
      /* implicit `return` */ 0
    when 1
      ; // no `break` or `return` -- falls through!
    else
      throw new RangeError 'bar must be 0 or 1'