Skip to content

[CSDiagnostics] Look through l-value conversions when mismatch is in … #41504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4563,6 +4563,14 @@ bool ConstraintSystem::repairFailures(
break;
}

// If this is a problem with result type of a subscript setter,
// let's re-attempt to repair without l-value conversion in the
// locator to fix underlying type mismatch.
if (path.back().is<LocatorPathElt::FunctionResult>()) {
return repairFailures(lhs, rhs, matchKind, conversionsOrFixes,
getConstraintLocator(anchor, path));
}

// If this is a function type param type mismatch in any position,
// the mismatch we want to report is for the whole structural type.
auto last = std::find_if(
Expand Down
24 changes: 24 additions & 0 deletions validation-test/Sema/SwiftUI/rdar84580119.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
// REQUIRES: objc_interop
// REQUIRES: OS=macosx

import SwiftUI

extension HorizontalAlignment {
private enum MyHorizontalAlignment: AlignmentID {
static func defaultValue(in d: ViewDimensions) -> CGFloat { d.width }
}
}

extension EnvironmentValues {
var myHorizontalAlignment: AlignmentID? {
get { fatalError() }
set { self[\.MyHorizontalAlignmentEnvironmentKey.self] = newValue }
// expected-error@-1 {{generic parameter 'K' could not be inferred}}
// expected-error@-2 {{cannot infer key path type from context; consider explicitly specifying a root type}}
}
}

struct MyHorizontalAlignmentEnvironmentKey: EnvironmentKey {
static var defaultValue: AlignmentID?
}