kyleect / locks

A toy language branched from Lox to learn language implementation and tooling. Forked from loxcraft
https://kyleect.github.io/locks/#/docs
MIT License
0 stars 0 forks source link

Explicit return on a class method using an expression body causes a syntax error on the class's body end bracket #129

Open kyleect opened 6 months ago

kyleect commented 6 months ago

Code

class Box {
  let value;

  fn init(value) {
    this.value = value;
  }

  fn get() => return this.value; // out: SyntaxError: unexpected "return"
}

https://kyleect.github.io/locks/#/?code=MYGwhgzhAEBCD2APaBvAUNaICmAXaAbmCAK7YDcaG0AZgHbQCWdjuAFEadgJSrWa4AFowgA6TmWgBeQsTKVMAX2pVM9aAHM8bXlIB80AE54ShhkJHi5FaAHpb0eCVwAuaAGUAnnVxhEAUUNDeEM3EjpsRAAHbGBcbAATaAAiY1xTOmS0ZSA

Error

error[SyntaxError]: unexpected "return"
  ┌─ <script>:9:15
  │
9 │   fn get() => return this.value; // out: SyntaxError: unexpected "return"
  │               ^^^^^^
  │
  = expected: "!", "(", "-", "[", "false", "nil", "super", "this", "true", identifier, number, or string

error[SyntaxError]: unexpected "}"
   ┌─ <script>:10:1
   │
10 │ }
   │ ^
   │
   = expected: "!", "(", "-", "[", "class", "false", "fn", "for", "if", "let", "nil", "print", "return", "super", "this", "true", "while", "{", identifier, number, or string