Skip to content

Commit 333a1eb

Browse files
authored
Merge pull request #79192 from rintaro/ifconfig-allactive-postfixexpr
[Parse] Adjust assertions for ParsingFlags::PoundIfAllActive mode
2 parents 1fcb944 + 635494d commit 333a1eb

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,11 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
15031503
continue;
15041504

15051505
// Extract the parsed expression as the result.
1506-
assert(activeElements.size() == 1 && activeElements[0].is<Expr *>());
1506+
assert(activeElements.size() == 1 ||
1507+
SF.getParsingOptions().contains(
1508+
SourceFile::ParsingFlags::PoundIfAllActive));
1509+
// FIXME: 'PoundIfAllActive' mode should keep all the parsed AST nodes.
1510+
assert(activeElements[0].is<Expr *>());
15071511
auto expr = activeElements[0].get<Expr *>();
15081512
ParserStatus status(ICD);
15091513
auto charRange = Lexer::getCharSourceRangeFromSourceRange(

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,20 @@ class A {
184184
@IBAction @objc func foo(a: Int) {}
185185
#endif
186186
}
187+
188+
func testPostfixIfConfig() {
189+
foo
190+
#if FLAG1
191+
.flag1
192+
#if FLAG2
193+
.flag2
194+
#elseif FLAG3
195+
.flag3
196+
#else
197+
.else1
198+
#endif
199+
.flag1Tail
200+
#else
201+
.else2
202+
#endif
203+
}

test/SourceKit/DocumentStructure/structure.swift.empty.response

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2930,
3+
key.length: 3126,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1669,6 +1669,17 @@
16691669
]
16701670
}
16711671
]
1672+
},
1673+
{
1674+
key.kind: source.lang.swift.decl.function.free,
1675+
key.accessibility: source.lang.swift.accessibility.internal,
1676+
key.name: "testPostfixIfConfig()",
1677+
key.offset: 2931,
1678+
key.length: 194,
1679+
key.nameoffset: 2936,
1680+
key.namelength: 21,
1681+
key.bodyoffset: 2959,
1682+
key.bodylength: 165
16721683
}
16731684
],
16741685
key.diagnostics: [

test/SourceKit/DocumentStructure/structure.swift.foobar.response

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2930,
3+
key.length: 3126,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1669,6 +1669,17 @@
16691669
]
16701670
}
16711671
]
1672+
},
1673+
{
1674+
key.kind: source.lang.swift.decl.function.free,
1675+
key.accessibility: source.lang.swift.accessibility.internal,
1676+
key.name: "testPostfixIfConfig()",
1677+
key.offset: 2931,
1678+
key.length: 194,
1679+
key.nameoffset: 2936,
1680+
key.namelength: 21,
1681+
key.bodyoffset: 2959,
1682+
key.bodylength: 165
16721683
}
16731684
],
16741685
key.diagnostics: [

test/SourceKit/DocumentStructure/structure.swift.response

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2930,
3+
key.length: 3126,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1669,6 +1669,17 @@
16691669
]
16701670
}
16711671
]
1672+
},
1673+
{
1674+
key.kind: source.lang.swift.decl.function.free,
1675+
key.accessibility: source.lang.swift.accessibility.internal,
1676+
key.name: "testPostfixIfConfig()",
1677+
key.offset: 2931,
1678+
key.length: 194,
1679+
key.nameoffset: 2936,
1680+
key.namelength: 21,
1681+
key.bodyoffset: 2959,
1682+
key.bodylength: 165
16721683
}
16731684
],
16741685
key.diagnostics: [

0 commit comments

Comments
 (0)