Skip to content

[5.7][CSDiagnostics] Verify that member is in collection context #60628

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
Aug 19, 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
13 changes: 5 additions & 8 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3885,17 +3885,14 @@ bool MissingMemberFailure::diagnoseInLiteralCollectionContext() const {
if (!parentExpr)
return false;

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

if (!parentType->isKnownStdlibCollectionType() && !parentType->is<TupleType>())
if (!isExpr<CollectionExpr>(parentExpr))
return false;

if (isa<TupleExpr>(parentExpr)) {
parentExpr = findParentExpr(parentExpr);
if (!parentExpr)
return false;
}

if (auto *defaultableVar =
getRawType(parentExpr)->getAs<TypeVariableType>()) {
if (solution.DefaultedConstraints.count(
Expand Down
20 changes: 20 additions & 0 deletions test/expr/closure/multi_statement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,23 @@ func test_conflicting_pattern_vars() {
}
}
}

// rdar://91452726 - crash in MissingMemberFailure::diagnoseInLiteralCollectionContext
struct Test {
struct ID {
}

enum E : Hashable, Equatable {
case id
}

var arr: [(ID, E)]

func test() {
_ = arr.map { v in
switch v {
case .id: return true // expected-error {{value of tuple type '(Test.ID, Test.E)' has no member 'id'}}
}
}
}
}