Skip to content

Detect correct missing open brace #53

Description

@jkeiser

Right now, this will report closing { without open } on the end brace, which makes it really hard to find out where the actual error was. Indentation makes it pretty clear, so we should modify the rules to make it better:

MyClass: {
    Function1: {
        if (:x == :y) # this is the line with the missing {
           10
        } # error SHOULD be reported here
    }
    Function2: {
        :x + :y
    }
} # error is reported here

Activity

  1. jkeiser commented on Apr 30, 2019

    @jkeiser
    MemberAuthor

    One way to do this would be to require close braces to be on the same block level as the opening brace. However, we allow expressions to be continued on indented lines in order to support things like this:

    :x = if y > 0 {
            1000 / y
         } else { # this close brace is not on the same indent level as the corresponding opening brace
             0
         }
    
  2. jkeiser commented on Apr 30, 2019

    @jkeiser
    MemberAuthor

    A rule that might work, however, would be "a close operator MUST close something from either the current line or the last open line." That would mean:

    # this is OK
    MyFunction: {
        if y > 0 {
            1000/y
        } else {
            0
        }
    }
    
    # this is OK
    MyFunction: {
        x = if y > 0 {
               1000 / y
           } else {
               0
           }
    }
    
    # this is an error
    MyFunction: {
        # we will guess the open brace needs to be here
        y = :y + 1
        if y > 0
            1000/y
        } else { # error: this close brace causes both "if y > 0 ..." and its parent, "MyFunction: {", to be closed.         
            0
        }
    }
    
    # this is an error
    MyFunction: {
        y = :y + 1
        if y > 0 {
            # we will estimate the close brace here
            1000/y
            } else { # error: this close brace causes both "1000/y" and its parent, "if y > 0 {", to be closed.
                0
            }
    }
    
    # this is ok :/
    MyFunction: {
        y = :y + 1
        if y > 0 {
                1000/y
            } else {
                0
            }
    }
    
  3. jkeiser commented on Apr 30, 2019

    @jkeiser
    MemberAuthor

    This rule could be expanded reasonably to include other operators:

    x = 10 + 20
      + 30 + 40
          + 50 + 60; y = 10 # semicolon would be an error
    
    x = 10 * 20
      * 30 * 40 *
        50 + 60 # error: + closes the * two lines above
    
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