DanielXMoore / Civet

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

Parse error in class method with return type and < #1590

Closed unlessgames closed 1 week ago

unlessgames commented 2 weeks ago

Trying to upgrade to newer civet version (from 0.6.x), I get some errors in my code, like this won't parse anymore

class A
  fn(i: number): string
    if i < 10
      "a"
    else # <--- parse error here 
      "b"

The same thing parses fine outside of a class

fn := (i: number) : string =>
    if i < 10
      "a"
    else 
      "b"

or using do

class A
  fn(i: number) : string do
    if i < 10
      "a"
    else 
      "b"
bbrk24 commented 2 weeks ago

The same thing parses fine outside of a class

fn := (i: number) : string =>
    if i < 10
      "a"
    else 
      "b"

The reason this works is because it's an arrow. Using a function instead also doesn't parse:

function fn(i: number): string
    if i < 10
      "a"
    else 
      "b"