Skip to content

Commit b90fc2b

Browse files
committed
[CSOptimizer] Don't attempt to walk into literals while analyzing operator chains
Most of them don't have any children but string interpolation does and that marks whole chain as unsupported.
1 parent 3616dab commit b90fc2b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ static Type inferTypeOfArithmeticOperatorChain(DeclContext *dc, ASTNode node) {
500500
}
501501

502502
literals.insert(defaultTy);
503-
return Action::Continue(expr);
503+
// String interpolation expressions have `TapExpr`
504+
// as their children, no reason to walk them.
505+
return Action::SkipChildren(expr);
504506
}
505507
}
506508
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %scale-test --begin 1 --end 10 --step 1 --select NumLeafScopes %s -Xfrontend=-typecheck
2+
// REQUIRES: asserts,no_asan
3+
4+
struct MyString {
5+
}
6+
7+
extension MyString: ExpressibleByStringLiteral {
8+
init(stringLiteral value: String) {}
9+
}
10+
11+
func +(_: MyString, _: MyString) -> MyString {}
12+
13+
func test(_: @autoclosure () -> String) {}
14+
func test(_: () -> String) {}
15+
func test(_: Character) {}
16+
17+
func test(names: [String]) {
18+
var resultString = ""
19+
for name in names {
20+
test("\(name)"
21+
%for i in range(0, N):
22+
+ "\(name)"
23+
%end
24+
+ "\(name)")
25+
}
26+
}

0 commit comments

Comments
 (0)