Skip to content

Commit ade019d

Browse files
authored
Merge pull request #4375 from milseman/3_0_id_as_any
[3.0] [id as Any] Coerce keys to rvalues for checking Hashable conformance
2 parents acfa54e + cb9cf69 commit ade019d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,6 +5337,10 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
53375337
expr = coerceImplicitlyUnwrappedOptionalToValue(expr, objTy, locator);
53385338
}
53395339

5340+
// We want to check conformance on the rvalue, as that's what has
5341+
// the Hashable conformance
5342+
expr = tc.coerceToRValue(expr);
5343+
53405344
// Find the conformance of the source type to Hashable.
53415345
auto hashable = tc.Context.getProtocol(KnownProtocolKind::Hashable);
53425346
ProtocolConformance *conformance;

test/Constraints/anyhashable-collection-cast.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ func test() {
1515
print(s)
1616
}
1717
}
18+
19+
func testLValueCoerce() {
20+
var lvalue = "lvalue"
21+
var map: [AnyHashable : Any] = [lvalue: lvalue]
22+
lvalue = map[lvalue] as! String
23+
}

0 commit comments

Comments
 (0)