Skip to content

Commit c22649e

Browse files
authored
Merge pull request #41504 from xedin/rdar-84580119
[CSDiagnostics] Look through l-value conversions when mismatch is in …
2 parents 8e071f7 + bf820c5 commit c22649e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,6 +4563,14 @@ bool ConstraintSystem::repairFailures(
45634563
break;
45644564
}
45654565

4566+
// If this is a problem with result type of a subscript setter,
4567+
// let's re-attempt to repair without l-value conversion in the
4568+
// locator to fix underlying type mismatch.
4569+
if (path.back().is<LocatorPathElt::FunctionResult>()) {
4570+
return repairFailures(lhs, rhs, matchKind, conversionsOrFixes,
4571+
getConstraintLocator(anchor, path));
4572+
}
4573+
45664574
// If this is a function type param type mismatch in any position,
45674575
// the mismatch we want to report is for the whole structural type.
45684576
auto last = std::find_if(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import SwiftUI
6+
7+
extension HorizontalAlignment {
8+
private enum MyHorizontalAlignment: AlignmentID {
9+
static func defaultValue(in d: ViewDimensions) -> CGFloat { d.width }
10+
}
11+
}
12+
13+
extension EnvironmentValues {
14+
var myHorizontalAlignment: AlignmentID? {
15+
get { fatalError() }
16+
set { self[\.MyHorizontalAlignmentEnvironmentKey.self] = newValue }
17+
// expected-error@-1 {{generic parameter 'K' could not be inferred}}
18+
// expected-error@-2 {{cannot infer key path type from context; consider explicitly specifying a root type}}
19+
}
20+
}
21+
22+
struct MyHorizontalAlignmentEnvironmentKey: EnvironmentKey {
23+
static var defaultValue: AlignmentID?
24+
}

0 commit comments

Comments
 (0)