Skip to content

[parser] Flow types and syntax errors in function bodies #38

Open

Description

@wcjohnson

lightscript@0.5.9:

a(b?: T1): T2 ->
  switch
unknown: Unexpected token (1:4)
> 1 | a(b?: T1): T2 ->
    |     ^
  2 |   switch
  3 | 

The parser is misattributing the syntax error to the function arg list, rather than the body. Removing the return type annotation fixes this and gives the proper syntax error:

a(b?: T1) ->
  switch
unknown: Illegal newline. (2:8)
  1 | a(b?: T1) ->
> 2 |   switch
    |         ^
  3 | 

I have traced the problem to this area:
https://github.com/lightscript/babylon-lightscript/blob/master/src/parser/expression.js#L477

I think the preceding code, when it tries to speculatively parse a function with a flowtype, is encountering an error in the body and eating it/resetting the state. Then because the refShorthandDefaultPos is set, the error appears outside the function body.

No suggested fix yet but I am looking into it.

Activity

  1. wcjohnson commented on Jun 20, 2017

    @wcjohnson
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions