Skip to content

Commit 907b069

Browse files
Merge pull request swiftlang#34330 from LucianoPAlmeida/SR-13732-crash-invalid
[SR-13732] [Sema] Fix crash on simplifyFix constraint for tuple mismatch
2 parents bd6cc58 + 8858152 commit 907b069

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,8 +3160,7 @@ class ConstraintSystem {
31603160
/// subsequent solution would be worse than the best known solution.
31613161
bool recordFix(ConstraintFix *fix, unsigned impact = 1);
31623162

3163-
void recordPotentialHole(TypeVariableType *typeVar);
3164-
void recordPotentialHole(FunctionType *fnType);
3163+
void recordPotentialHole(Type type);
31653164

31663165
void recordTrailingClosureMatch(
31673166
ConstraintLocator *locator,

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9913,16 +9913,11 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
99139913
return false;
99149914
}
99159915

9916-
void ConstraintSystem::recordPotentialHole(TypeVariableType *typeVar) {
9917-
assert(typeVar);
9918-
typeVar->getImpl().enableCanBindToHole(getSavedBindings());
9919-
}
9920-
9921-
void ConstraintSystem::recordPotentialHole(FunctionType *fnType) {
9922-
assert(fnType);
9923-
Type(fnType).visit([&](Type type) {
9916+
void ConstraintSystem::recordPotentialHole(Type type) {
9917+
assert(type->hasTypeVariable());
9918+
type.visit([&](Type type) {
99249919
if (auto *typeVar = type->getAs<TypeVariableType>())
9925-
recordPotentialHole(typeVar);
9920+
typeVar->getImpl().enableCanBindToHole(getSavedBindings());
99269921
});
99279922
}
99289923

@@ -10024,7 +10019,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1002410019
newTupleTypes.push_back(smallerElt);
1002510020
} else {
1002610021
if (largerElt.getType()->isTypeVariableOrMember())
10027-
recordPotentialHole(largerElt.getType()->getAs<TypeVariableType>());
10022+
recordPotentialHole(largerElt.getType());
1002810023
}
1002910024
}
1003010025
auto matchingType =

test/Constraints/lvalues.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,28 @@ func wump<T>(to: T, _ body: (G<T>) -> ()) {}
241241

242242
wump(to: 0, { $0[] = 0 })
243243
// expected-error@-1 {{missing argument for parameter #1 in call}}
244+
245+
// SR-13732
246+
extension MutableCollection {
247+
public mutating func writePrefix<I: IteratorProtocol>(from source: inout I)
248+
-> (writtenCount: Int, afterLastWritten: Index)
249+
where I.Element == Element
250+
{
251+
fatalError()
252+
}
253+
254+
public mutating func writePrefix<Source: Collection>(from source: Source)
255+
-> (writtenCount: Int, afterLastWritten: Index, afterLastRead: Source.Index)
256+
where Source.Element == Element
257+
{
258+
fatalError()
259+
}
260+
261+
}
262+
263+
func testWritePrefixIterator() {
264+
var a = Array(0..<10)
265+
266+
var underflow = (1..<10).makeIterator()
267+
var (writtenCount, afterLastWritten) = a.writePrefix(from: underflow) // expected-error {{passing value of type 'IndexingIterator<(Range<Int>)>' to an inout parameter requires explicit '&'}} {{62-62=&}}
268+
}

0 commit comments

Comments
 (0)