Skip to content

Commit 1975b10

Browse files
committed
Sema: Fix recently-introduced crash with diagnostics of inout parameters
Recently TupleTypeElt was changed to add an inout bit. It is no longer valid to construct tuple types whose elements have InOutType, and instead the flag on the element must be set instead. Update diagnoseImplicitSelfErrors() for the new convention. Fixes the only remaining crash in the test case from <rdar://19569255>, but the original issue were fixed long ago.
1 parent bf2ca1a commit 1975b10

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4747,13 +4747,17 @@ static bool diagnoseImplicitSelfErrors(Expr *fnExpr, Expr *argExpr,
47474747
// matches what the user actually wrote instead of what the typechecker
47484748
// expects.
47494749
SmallVector<TupleTypeElt, 4> elts;
4750-
for (auto *el : argTuple->getElements()) {
4750+
for (unsigned i = 0, e = argTuple->getNumElements(); i < e; ++i) {
47514751
ConcreteDeclRef ref = nullptr;
4752+
auto *el = argTuple->getElement(i);
47524753
auto typeResult =
47534754
TC.getTypeOfExpressionWithoutApplying(el, CS.DC, ref);
47544755
if (!typeResult)
47554756
return false;
4756-
elts.push_back(typeResult);
4757+
auto flags = ParameterTypeFlags().withInOut(typeResult->is<InOutType>());
4758+
elts.push_back(TupleTypeElt(typeResult->getInOutObjectType(),
4759+
argTuple->getElementName(i),
4760+
flags));
47574761
}
47584762

47594763
argType = TupleType::get(elts, CS.getASTContext());

test/Constraints/members.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,15 @@ extension Array where Element == Int {
417417
// expected-error@-1 {{use of 'min' nearly matches global function 'min' in module 'Swift' rather than instance method 'min()'}}
418418
}
419419
}
420+
421+
// Crash in diagnoseImplicitSelfErrors()
422+
423+
struct Aardvark {
424+
var snout: Int
425+
426+
mutating func burrow() {
427+
dig(&snout, .y) // expected-error {{type 'Int' has no member 'y'}}
428+
}
429+
430+
func dig(_: inout Int, _: Int) {}
431+
}

0 commit comments

Comments
 (0)