Skip to content

Commit 57c7317

Browse files
authored
Merge pull request #60628 from xedin/rdar-91452726-5.7
[5.7][CSDiagnostics] Verify that member is in collection context
2 parents 04310e9 + 13f18a5 commit 57c7317

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,17 +3885,14 @@ bool MissingMemberFailure::diagnoseInLiteralCollectionContext() const {
38853885
if (!parentExpr)
38863886
return false;
38873887

3888-
auto parentType = getType(parentExpr);
3888+
// This could happen if collection is a dictionary literal i.e.
3889+
// ["a": .test] - the element is a tuple - ("a", .test).
3890+
if (isExpr<TupleExpr>(parentExpr))
3891+
parentExpr = findParentExpr(parentExpr);
38893892

3890-
if (!parentType->isKnownStdlibCollectionType() && !parentType->is<TupleType>())
3893+
if (!isExpr<CollectionExpr>(parentExpr))
38913894
return false;
38923895

3893-
if (isa<TupleExpr>(parentExpr)) {
3894-
parentExpr = findParentExpr(parentExpr);
3895-
if (!parentExpr)
3896-
return false;
3897-
}
3898-
38993896
if (auto *defaultableVar =
39003897
getRawType(parentExpr)->getAs<TypeVariableType>()) {
39013898
if (solution.DefaultedConstraints.count(

test/expr/closure/multi_statement.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,23 @@ func test_conflicting_pattern_vars() {
515515
}
516516
}
517517
}
518+
519+
// rdar://91452726 - crash in MissingMemberFailure::diagnoseInLiteralCollectionContext
520+
struct Test {
521+
struct ID {
522+
}
523+
524+
enum E : Hashable, Equatable {
525+
case id
526+
}
527+
528+
var arr: [(ID, E)]
529+
530+
func test() {
531+
_ = arr.map { v in
532+
switch v {
533+
case .id: return true // expected-error {{value of tuple type '(Test.ID, Test.E)' has no member 'id'}}
534+
}
535+
}
536+
}
537+
}

0 commit comments

Comments
 (0)