Skip to content

Commit 5418e8d

Browse files
committed
[AST] Remove ArgumentList::composeTupleOrParenType
Remove a redundant bit of diagnostic logic now that we better diagnose cases where an uncallable variable is in an overload set for a mismatched apply. Tweak another bit of diagnostic logic to only apply to a single arg/param case, as that seems to be what it's meant for.
1 parent 4915513 commit 5418e8d

File tree

5 files changed

+6
-59
lines changed

5 files changed

+6
-59
lines changed

include/swift/AST/ArgumentList.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,6 @@ class alignas(Argument) ArgumentList final
527527
ASTContext &ctx,
528528
llvm::function_ref<Type(Expr *)> getType = __Expr_getType) const;
529529

530-
/// Avoid adding new usages of this. Creates a TupleType or ParenType
531-
/// representing the types in the argument list. A ParenType will be returned
532-
/// for a single argument, otherwise a TupleType.
533-
Type composeTupleOrParenType(
534-
ASTContext &ctx,
535-
llvm::function_ref<Type(Expr *)> getType = __Expr_getType) const;
536-
537530
/// Whether the argument list matches a given parameter list. This will return
538531
/// \c false if the arity doesn't match, or any of the canonical types or
539532
/// labels don't match. Note that this expects types to be present for the

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ ERROR(cannot_pass_rvalue_inout,none,
256256
ERROR(cannot_provide_default_value_inout,none,
257257
"cannot provide default value to inout parameter %0", (Identifier))
258258

259-
ERROR(cannot_call_with_params, none,
260-
"cannot invoke %select{|initializer for type }2'%0' with an argument list"
261-
" of type '%1'", (StringRef, StringRef, bool))
262-
263259
ERROR(cannot_call_non_function_value,none,
264260
"cannot call value of non-function type %0", (Type))
265261

lib/AST/ArgumentList.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -262,32 +262,6 @@ Expr *ArgumentList::packIntoImplicitTupleOrParen(
262262
return tuple;
263263
}
264264

265-
Type ArgumentList::composeTupleOrParenType(
266-
ASTContext &ctx, llvm::function_ref<Type(Expr *)> getType) const {
267-
if (auto *unary = getUnlabeledUnaryExpr()) {
268-
auto ty = getType(unary);
269-
assert(ty);
270-
ParameterTypeFlags flags;
271-
if (get(0).isInOut()) {
272-
ty = ty->getInOutObjectType();
273-
flags = flags.withInOut(true);
274-
}
275-
return ParenType::get(ctx, ty, flags);
276-
}
277-
SmallVector<TupleTypeElt, 4> elts;
278-
for (auto arg : *this) {
279-
auto ty = getType(arg.getExpr());
280-
assert(ty);
281-
ParameterTypeFlags flags;
282-
if (arg.isInOut()) {
283-
ty = ty->getInOutObjectType();
284-
flags = flags.withInOut(true);
285-
}
286-
elts.emplace_back(ty, arg.getLabel(), flags);
287-
}
288-
return TupleType::get(elts, ctx);
289-
}
290-
291265
bool ArgumentList::matches(ArrayRef<AnyFunctionType::Param> params,
292266
llvm::function_ref<Type(Expr *)> getType) const {
293267
if (size() != params.size())

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6991,20 +6991,6 @@ bool ExtraneousCallFailure::diagnoseAsError() {
69916991
}
69926992
}
69936993

6994-
if (auto *UDE = getAsExpr<UnresolvedDotExpr>(anchor)) {
6995-
auto *baseExpr = UDE->getBase();
6996-
auto *call = castToExpr<CallExpr>(getRawAnchor());
6997-
6998-
if (getType(baseExpr)->isAnyObject()) {
6999-
auto argsTy = call->getArgs()->composeTupleOrParenType(
7000-
getASTContext(), [&](Expr *E) { return getType(E); });
7001-
emitDiagnostic(diag::cannot_call_with_params,
7002-
UDE->getName().getBaseName().userFacingName(),
7003-
argsTy.getString(), isa<TypeExpr>(baseExpr));
7004-
return true;
7005-
}
7006-
}
7007-
70086994
auto diagnostic =
70096995
emitDiagnostic(diag::cannot_call_non_function_value, getType(anchor));
70106996
removeParensFixIt(diagnostic);

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,19 +4403,17 @@ static bool diagnoseAmbiguity(
44034403
type->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
44044404
assert(fn);
44054405

4406-
if (fn->getNumParams() == 1) {
4407-
auto *argList =
4408-
solution.getArgumentList(solution.Fixes.front()->getLocator());
4409-
assert(argList);
4406+
auto *argList =
4407+
solution.getArgumentList(solution.Fixes.front()->getLocator());
4408+
assert(argList);
44104409

4410+
if (fn->getNumParams() == 1 && argList->isUnary()) {
44114411
const auto &param = fn->getParams()[0];
4412-
auto argType = argList->composeTupleOrParenType(
4413-
cs.getASTContext(),
4414-
[&](Expr *E) { return solution.getResolvedType(E); });
4412+
auto argTy = solution.getResolvedType(argList->getUnaryExpr());
44154413

44164414
DE.diagnose(noteLoc, diag::candidate_has_invalid_argument_at_position,
44174415
solution.simplifyType(param.getPlainType()),
4418-
/*position=*/1, param.isInOut(), argType);
4416+
/*position=*/1, param.isInOut(), argTy);
44194417
} else {
44204418
DE.diagnose(noteLoc, diag::candidate_partial_match,
44214419
fn->getParamListAsString(fn->getParams()));

0 commit comments

Comments
 (0)