Skip to content

Commit a046eaf

Browse files
committed
[ConstraintSystem] Adjust getFunctionArgApplyInfo to respect holes
Detect that direct callee couldn't be resolved e.g. due to an invalid reference or a missing member and fail instead of triggering an assert. Resolves: rdar://problem/71525503
1 parent 509f905 commit a046eaf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4408,9 +4408,16 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
44084408
// If we didn't resolve an overload for the callee, we should be dealing
44094409
// with a call of an arbitrary function expr.
44104410
auto *call = castToExpr<CallExpr>(anchor);
4411+
rawFnType = getType(call->getFn());
4412+
4413+
// If callee couldn't be resolved due to expression
4414+
// issues e.g. it's a reference to an invalid member
4415+
// let's just return here.
4416+
if (simplifyType(rawFnType)->is<UnresolvedType>())
4417+
return None;
4418+
44114419
assert(!shouldHaveDirectCalleeOverload(call) &&
44124420
"Should we have resolved a callee for this?");
4413-
rawFnType = getType(call->getFn());
44144421
}
44154422

44164423
// Try to resolve the function type by loading lvalues and looking through

test/Constraints/closures.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,3 +1042,17 @@ let explicitUnboundResult2: (Array<Bool>) -> Array<Int> = {
10421042
let explicitUnboundResult3: (Array<Bool>) -> Array<Int> = {
10431043
(arr: Array) -> Array in [true]
10441044
}
1045+
1046+
// rdar://problem/71525503 - Assertion failed: (!shouldHaveDirectCalleeOverload(call) && "Should we have resolved a callee for this?")
1047+
func test_inout_with_invalid_member_ref() {
1048+
struct S {
1049+
static func createS(_ arg: inout Int) -> S { S() }
1050+
}
1051+
class C {
1052+
static subscript(s: (Int) -> Void) -> Bool { get { return false } }
1053+
}
1054+
1055+
let _: Bool = C[{ .createS(&$0) }]
1056+
// expected-error@-1 {{value of tuple type 'Void' has no member 'createS'}}
1057+
// expected-error@-2 {{cannot pass immutable value as inout argument: '$0' is immutable}}
1058+
}

0 commit comments

Comments
 (0)