Skip to content

[Parse] Improve '#if' block parsing #7382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2017

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 10, 2017

First commit:

  • Don't emit duplicated error: expected #else or #endif at end of conditional compilation block.
    class Foo {
        #if true
          func foo() {}
    [EOF]
  • Improve error message when seeing } in config block. [Parse] Split declaration list parsing from parseList() #6005 (comment)
    class Foo {
    #if true
        func foo() {}
    }  // error: unexpected '}' in conditional compilation block
    #else
    #endif
    Previously:
    test.swift:4:1: error: expected declaration
    }
    ^
    test.swift:1:7: note: in declaration of 'Foo'
    class Foo {
          ^
    

Second commit:

  • Narrow allowance of 3+ components numeric literal to condition part of the directive.
    This code supposed be blocked by the Parser: expected named member of numeric literal.
    #if true
       let a = 3.3.4 // error: value of type 'Double' has no member '4'
    #endif
  • Allow 3+ components numeric literal in #if directive in decl list position as well.
    Previously, this is rejected:
    class C {
    #if swift(>=3.0.2)
      func foo() {}
    #endif
    }

@rintaro
Copy link
Member Author

rintaro commented Feb 10, 2017

@swift-ci Please smoke test

diagnose(Tok.getLoc(),
diag::unexpected_rbrace_in_conditional_compilation_block);
// If we see '}', following declarations don't look like belong to
// the current decl context; Skip them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔬 nit: no need to capitalize Skip

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳 Thanks!

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Rintaro!

* Don't emit duplicated 'expected #else or #endif at end of conditional
  compilation block' error.

    class Foo {
      #if true
        func foo() {}
    [EOF]

* Improve error message when seeing '}' in config block.

    class Foo {
    #if true
        func foo();
    } // error: unexpected '}' in conditional compilation block
    #else
    #endif
* Narrow allowance of 3+ components numeric literal to condition part of the
  directive.
* Allow 3+ components in '#if' directive in decl list position as well.
@rintaro rintaro force-pushed the parse-ifconfig-fix1 branch from 1968b40 to 3b42894 Compare February 16, 2017 02:36
@rintaro
Copy link
Member Author

rintaro commented Feb 16, 2017

@swift-ci Please smoke test

@rintaro rintaro merged commit cb8bbf0 into swiftlang:master Feb 16, 2017
@rintaro rintaro deleted the parse-ifconfig-fix1 branch February 16, 2017 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants