Skip to content

Commit 3fd9037

Browse files
committed
[ConstraintSystem] Don't produce argument info object for extraneous arguments
An extraneous argument doesn't have a corresponding parameter so the information object for such an argument is not safe to produce. Resolves: #60436 Resolves: rdar://98304482
1 parent 633cc34 commit 3fd9037

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,30 @@ class FunctionArgApplyInfo {
715715
FunctionType *FnType;
716716
const ValueDecl *Callee;
717717

718-
public:
719718
FunctionArgApplyInfo(ArgumentList *argList, Expr *argExpr, unsigned argIdx,
720719
Type argType, unsigned paramIdx, Type fnInterfaceType,
721720
FunctionType *fnType, const ValueDecl *callee)
722721
: ArgList(argList), ArgExpr(argExpr), ArgIdx(argIdx), ArgType(argType),
723722
ParamIdx(paramIdx), FnInterfaceType(fnInterfaceType), FnType(fnType),
724723
Callee(callee) {}
725724

725+
public:
726+
static Optional<FunctionArgApplyInfo>
727+
get(ArgumentList *argList, Expr *argExpr, unsigned argIdx, Type argType,
728+
unsigned paramIdx, Type fnInterfaceType, FunctionType *fnType,
729+
const ValueDecl *callee) {
730+
assert(fnType);
731+
732+
if (argIdx >= argList->size())
733+
return None;
734+
735+
if (paramIdx >= fnType->getNumParams())
736+
return None;
737+
738+
return FunctionArgApplyInfo(argList, argExpr, argIdx, argType, paramIdx,
739+
fnInterfaceType, fnType, callee);
740+
}
741+
726742
/// \returns The list of the arguments used for this application.
727743
ArgumentList *getArgList() const { return ArgList; }
728744

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5682,9 +5682,9 @@ Solution::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
56825682
auto argIdx = applyArgElt->getArgIdx();
56835683
auto paramIdx = applyArgElt->getParamIdx();
56845684

5685-
return FunctionArgApplyInfo(argList, argExpr, argIdx,
5686-
simplifyType(getType(argExpr)), paramIdx,
5687-
fnInterfaceType, fnType, callee);
5685+
return FunctionArgApplyInfo::get(argList, argExpr, argIdx,
5686+
simplifyType(getType(argExpr)), paramIdx,
5687+
fnInterfaceType, fnType, callee);
56885688
}
56895689

56905690
bool constraints::isKnownKeyPathType(Type type) {

test/Constraints/argument_matching.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,3 +1802,11 @@ do {
18021802
// expected-error@-1 {{cannot convert value of type 'Bool' to expected argument type 'String'}}
18031803
// expected-error@-2 {{missing argument label 'file:' in call}}
18041804
}
1805+
1806+
// https://github.com/apple/swift/issues/60436
1807+
func test_extraneous_argument_with_inout() {
1808+
func test(_: Int) {}
1809+
1810+
var x: Int = 0
1811+
test(42, &x) // expected-error {{extra argument in call}}
1812+
}

0 commit comments

Comments
 (0)