Skip to content

Commit 29ea599

Browse files
committed
[CSGen] Fix LinkedExprAnalyzer greedy operator linking
Let's not attempt to link arithmetic operators together in presence of concrete and literal types. Resolves: rdar://problem/35740653
1 parent 6c70718 commit 29ea599

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ namespace {
408408
// argument types, we can directly simplify the associated constraint
409409
// graph.
410410
auto simplifyBinOpExprTyVars = [&]() {
411+
// Don't attempt to do linking if there are
412+
// literals intermingled with other inferred types.
413+
if (lti.haveLiteral())
414+
return;
415+
411416
for (auto binExp1 : lti.binaryExprs) {
412417
for (auto binExp2 : lti.binaryExprs) {
413418
if (binExp1 == binExp2)

test/Constraints/operator.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,21 @@ func + (lhs: B_28688585, rhs: B_28688585) -> B_28688585 {
176176

177177
let var_28688585 = D_28688585(value: 1)
178178
_ = var_28688585 + var_28688585 + var_28688585 // Ok
179+
180+
// rdar://problem/35740653 - Fix `LinkedExprAnalyzer` greedy operator linking
181+
182+
struct S_35740653 {
183+
var v: Double = 42
184+
185+
static func value(_ value: Double) -> S_35740653 {
186+
return S_35740653(v: value)
187+
}
188+
189+
static func / (lhs: S_35740653, rhs: S_35740653) -> Double {
190+
return lhs.v / rhs.v
191+
}
192+
}
193+
194+
func rdar35740653(val: S_35740653) {
195+
let _ = 0...Int(val / .value(1.0 / 42.0)) // Ok
196+
}

0 commit comments

Comments
 (0)