Skip to content

[CSSimplify] Fix invalid diagnostics emitted for a pack reference outside of pack expansion #67489

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 3 commits into from
Jul 25, 2023
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
7 changes: 6 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5093,7 +5093,7 @@ bool ConstraintSystem::repairFailures(
if (auto objType = valueType->getOptionalObjectType())
valueType = objType;

if (rawReprType->isTypeVariableOrMember())
if (rawReprType->isTypeVariableOrMember() || rawReprType->isPlaceholder())
return false;

auto rawValue = isRawRepresentable(*this, rawReprType);
Expand Down Expand Up @@ -5350,6 +5350,11 @@ bool ConstraintSystem::repairFailures(
if (repairByUsingRawValueOfRawRepresentableType(lhs, rhs))
return true;

// If either side is a placeholder then let's consider this
// assignment correctly typed.
if (lhs->isPlaceholder() || rhs->isPlaceholder())
return true;

// Let's try to match source and destination types one more
// time to see whether they line up, if they do - the problem is
// related to immutability, otherwise it's a type mismatch.
Expand Down
12 changes: 12 additions & 0 deletions test/Constraints/pack-expansion-expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,15 @@ do {
_ = value.data.key // Ok
}
}

// rdar://110847476 - unrelated assignment and raw representable diagnostics
do {
struct Test<each Base: AsyncSequence> {
let base: (repeat each Base)

init(base: repeat each Base) {
self.base = base
// expected-error@-1 {{pack reference 'each Base' can only appear in pack expansion}}
}
}
}