Skip to content

Commit f8cc9b5

Browse files
[tests] Adjusting SR-12425 diagnostics tests
1 parent e17a934 commit f8cc9b5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ class CoercionAsForceCastFailure final : public ContextualFailure {
20232023
bool diagnoseAsError() override;
20242024
};
20252025

2026-
/// Diagnose an key path root type that cannot be applied to an instance
2026+
/// Diagnose n key path root type that cannot be applied to an instance
20272027
/// base that has another type.
20282028
///
20292029
/// \code

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3577,11 +3577,12 @@ bool ConstraintSystem::repairFailures(
35773577
break;
35783578
}
35793579

3580-
case ConstraintLocator::KeyPathRoot:
3580+
case ConstraintLocator::KeyPathRoot: {
35813581
conversionsOrFixes.push_back(AllowKeyPathRootTypeMismatch::create(
35823582
*this, lhs, rhs, getConstraintLocator(locator)));
35833583

35843584
break;
3585+
}
35853586

35863587
case ConstraintLocator::FunctionArgument: {
35873588
auto *argLoc = getConstraintLocator(

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,16 @@ internal var rightStructInstance: SR12425_R = SR12425_R()
811811

812812
public extension SR12425_R {
813813
subscript<T>(dynamicMember member: WritableKeyPath<SR12425_S, T>) -> T {
814-
// TODO(Diagnostics): bad diagnostic for member assign.
815-
// A better diagnostic would be: key path of type WritableKeyPath<SR12425_S, T> cannot be applied to a base of type SR12425_R
816-
get { rightStructInstance[keyPath: member] } // expected-error {{cannot convert return expression of type 'Any?' to return type 'T'}}
817-
set { rightStructInstance[keyPath: member] = newValue } // expected-error {{type of expression is ambiguous without more context}}
814+
get { rightStructInstance[keyPath: member] } // expected-error {{key path of type 'WritableKeyPath<SR12425_S, T>' cannot be applied to a base of type 'SR12425_R'}}
815+
set { rightStructInstance[keyPath: member] = newValue } // expected-error {{key path of type 'WritableKeyPath<SR12425_S, T>' cannot be applied to a base of type 'SR12425_R'}}
816+
}
817+
}
818+
819+
@dynamicMemberLookup
820+
public struct SR12425_R1 {}
821+
822+
public extension SR12425_R1 {
823+
subscript<T>(dynamicMember member: KeyPath<SR12425_R1, T>) -> T {
824+
get { rightStructInstance[keyPath: member] } // expected-error {{key path of type 'KeyPath<SR12425_R1, T>' cannot be applied to a base of type 'SR12425_R'}}
818825
}
819826
}

0 commit comments

Comments
 (0)