forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Parse] Handle
#if
in brace skipping logic
Previously we would strictly match `{` + `}`, but that ignored the fact that when parsing we consider `#if` + `#endif` to be a stronger delimiter than `{` + `}`, so can ignore a stray `}` in a `#if`. Update the logic to also track opening and closing `#if` decls, ignoring any braces that happen within them. rdar://129195380
- Loading branch information
1 parent
a85ca13
commit eeced06
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: not %target-swift-frontend -experimental-skip-all-function-bodies -dump-parse %s | %FileCheck %s | ||
|
||
// rdar://129195380 - Make sure the skipping logic can handle #if. | ||
struct S { | ||
// CHECK: func_decl{{.*}}:[[@LINE+1]]:3 - line:[[@LINE+11]]:3{{.*}}"foo()" | ||
func foo() { | ||
#if true | ||
} | ||
#if true | ||
func bar() { | ||
#else | ||
} | ||
#endif | ||
} | ||
#endif | ||
} | ||
// CHECK: func_decl{{.*}}:[[@LINE+1]]:3 - line:[[@LINE+1]]:15{{.*}}"baz()" | ||
func baz() {} | ||
} | ||
|
||
// The '#if' is unterminated here, so swallows the rest of the file. | ||
// CHECK: struct_decl{{.*}}:[[@LINE+1]]:1 - line:[[@LINE+14]]:14{{.*}}"R" | ||
struct R { | ||
#if false | ||
} | ||
#if true | ||
} | ||
#endif | ||
} | ||
#else | ||
} | ||
// CHECK-NOT: qux | ||
func qux() {} | ||
} | ||
|
||
func flim() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// rdar://129195380 - Make sure we correctly handle '#if' when skipping function | ||
// bodies. | ||
class C { | ||
func test1() { | ||
#if FOOBAR | ||
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 2):5 %s -- %s -DFOOBAR | ||
// RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):5 %s -- %s | ||
abc | ||
} | ||
|
||
func test2() { | ||
} | ||
} |