Crell / enum-comparison

A comparison of enumerations and similar features in different languages
80 stars 7 forks source link

No semi-colon after case with body #26

Closed iluuu1994 closed 3 years ago

iluuu1994 commented 3 years ago

From the RFC:

enum Suit implements Colorful {
  case Hearts {
    public function color(): string {
      return "Red";
    }
  };  // Note the semi-colon here!
}

I think there should be no semi-colon here. This way we're consistent with methods with or with no body.

abstract class Foo {
    function bar();
    function baz() {}; // Syntax error, unexpected token ";"
}

https://3v4l.org/Y0Fe1

Thoughts?

Crell commented 3 years ago

I'm fine with it. My concern is that the syntax then becomes

case Foo; or case Foo { ... }

So you end up with a semi-colon OR a closing brace. That feels inconsistent, and I don't know if there are parser implications. But I don't feel strongly either way.

iluuu1994 commented 3 years ago

@Crell I just feel like that would be more consistent with existing language constructs.

if ($x);
if ($x) {}

while ($x);
while ($x) {}

function foo();
function foo() {}

etc.

Crell commented 3 years ago

Fair. I'll update that once the primitive PR is merged. Want to do that for now at least as a discussion point, or is there more to adjust for now?

iluuu1994 commented 3 years ago

Feel free to merge the PR and I'll adjust that afterwards.