@@ -1915,134 +1915,6 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
1915
1915
return false ;
1916
1916
}
1917
1917
1918
- class ArgumentMatcher : public MatchCallArgumentListener {
1919
- Expr *ArgExpr;
1920
- ArrayRef<AnyFunctionType::Param> &Parameters;
1921
- const ParameterListInfo &ParamInfo;
1922
- SmallVectorImpl<AnyFunctionType::Param> &Arguments;
1923
-
1924
- CalleeCandidateInfo CandidateInfo;
1925
-
1926
- // Indicates if problem has been found and diagnostic was emitted.
1927
- bool Diagnosed = false ;
1928
- // Indicates if functions we are trying to call is a subscript.
1929
- bool IsSubscript;
1930
-
1931
- // Stores parameter bindings determined by call to matchCallArguments.
1932
- SmallVector<ParamBinding, 4 > Bindings;
1933
-
1934
- public:
1935
- ArgumentMatcher (Expr *argExpr,
1936
- ArrayRef<AnyFunctionType::Param> ¶ms,
1937
- const ParameterListInfo ¶mInfo,
1938
- SmallVectorImpl<AnyFunctionType::Param> &args,
1939
- CalleeCandidateInfo &CCI, bool isSubscript)
1940
- : ArgExpr(argExpr), Parameters(params),
1941
- ParamInfo (paramInfo), Arguments(args), CandidateInfo(CCI),
1942
- IsSubscript(isSubscript) {}
1943
-
1944
- bool outOfOrderArgument (unsigned argIdx, unsigned prevArgIdx) override {
1945
- auto &cs = CandidateInfo.CS ;
1946
- OutOfOrderArgumentFailure failure (nullptr , cs, argIdx, prevArgIdx, Bindings,
1947
- cs.getConstraintLocator (ArgExpr));
1948
- Diagnosed = failure.diagnoseAsError ();
1949
- return true ;
1950
- }
1951
-
1952
- bool relabelArguments (ArrayRef<Identifier> newNames) override {
1953
- assert (!newNames.empty () && " No arguments were re-labeled" );
1954
-
1955
- // Let's diagnose labeling problem but only related to corrected ones.
1956
- if (diagnoseArgumentLabelError (CandidateInfo.CS .getASTContext (), ArgExpr,
1957
- newNames, IsSubscript))
1958
- Diagnosed = true ;
1959
-
1960
- return true ;
1961
- }
1962
-
1963
- bool diagnose () {
1964
- // Use matchCallArguments to determine how close the argument list is (in
1965
- // shape) to the specified candidates parameters. This ignores the
1966
- // concrete types of the arguments, looking only at the argument labels.
1967
- matchCallArguments (Arguments, Parameters, ParamInfo,
1968
- CandidateInfo.hasTrailingClosure ,
1969
- /* allowFixes:*/ true , *this , Bindings);
1970
-
1971
- return Diagnosed;
1972
- }
1973
- };
1974
-
1975
- // / Emit a class of diagnostics that we only know how to generate when
1976
- // / there is exactly one candidate we know about. Return true if an error
1977
- // / is emitted.
1978
- static bool
1979
- diagnoseSingleCandidateFailures (CalleeCandidateInfo &CCI, Expr *fnExpr,
1980
- Expr *argExpr,
1981
- ArrayRef<Identifier> argLabels) {
1982
- // We only handle the situation where there is exactly one candidate
1983
- // here.
1984
- if (CCI.size () != 1 )
1985
- return false ;
1986
-
1987
- auto candidate = CCI[0 ];
1988
-
1989
- if (!candidate.hasParameters ())
1990
- return false ;
1991
-
1992
- auto params = candidate.getParameters ();
1993
- auto paramInfo = candidate.getParameterListInfo (params);
1994
- auto args = decomposeArgType (CCI.CS .getType (argExpr), argLabels);
1995
-
1996
- // Check the case where a raw-representable type is constructed from an
1997
- // argument with the same type:
1998
- //
1999
- // MyEnumType(MyEnumType.foo)
2000
- //
2001
- // This is missing 'rawValue:' label, but a better fix is to just remove
2002
- // the unnecessary constructor call:
2003
- //
2004
- // MyEnumType.foo
2005
- //
2006
- if (params.size () == 1 && args.size () == 1 && candidate.getDecl () &&
2007
- isa<ConstructorDecl>(candidate.getDecl ()) && candidate.skipCurriedSelf ) {
2008
- AnyFunctionType::Param &arg = args[0 ];
2009
- auto resTy =
2010
- candidate.getResultType ()->lookThroughAllOptionalTypes ();
2011
- auto rawTy = isRawRepresentable (CCI.CS , resTy);
2012
- if (rawTy && arg.getOldType () && resTy->isEqual (arg.getOldType ())) {
2013
- auto getInnerExpr = [](Expr *E) -> Expr * {
2014
- auto *parenE = dyn_cast<ParenExpr>(E);
2015
- if (!parenE)
2016
- return nullptr ;
2017
- return parenE->getSubExpr ();
2018
- };
2019
- Expr *innerE = getInnerExpr (argExpr);
2020
-
2021
- InFlightDiagnostic diag = CCI.CS .getASTContext ().Diags .diagnose (
2022
- fnExpr->getLoc (),
2023
- diag::invalid_initialization_parameter_same_type, resTy);
2024
- diag.highlight ((innerE ? innerE : argExpr)->getSourceRange ());
2025
- if (innerE) {
2026
- // Remove the unnecessary constructor call.
2027
- diag.fixItRemoveChars (fnExpr->getLoc (), innerE->getStartLoc ())
2028
- .fixItRemove (argExpr->getEndLoc ());
2029
- }
2030
- return true ;
2031
- }
2032
- }
2033
-
2034
- // We only handle structural errors here.
2035
- if (CCI.closeness != CC_ArgumentLabelMismatch &&
2036
- CCI.closeness != CC_ArgumentCountMismatch)
2037
- return false ;
2038
-
2039
- // If we have a single candidate that failed to match the argument list,
2040
- // attempt to use matchCallArguments to diagnose the problem.
2041
- return ArgumentMatcher (argExpr, params, paramInfo, args, CCI,
2042
- isa<SubscriptExpr>(fnExpr))
2043
- .diagnose ();
2044
- }
2045
-
2046
1918
// Extract expression for failed argument number
2047
1919
static Expr *getFailedArgumentExpr (CalleeCandidateInfo CCI, Expr *argExpr) {
2048
1920
if (auto *TE = dyn_cast<TupleExpr>(argExpr))
@@ -2094,11 +1966,6 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
2094
1966
if (diagnoseImplicitSelfErrors (fnExpr, argExpr, CCI, argLabels))
2095
1967
return true ;
2096
1968
2097
- // Do all the stuff that we only have implemented when there is a single
2098
- // candidate.
2099
- if (diagnoseSingleCandidateFailures (CCI, fnExpr, argExpr, argLabels))
2100
- return true ;
2101
-
2102
1969
// If we have a failure where the candidate set differs on exactly one
2103
1970
// argument, and where we have a consistent mismatch across the candidate set
2104
1971
// (often because there is only one candidate in the set), then diagnose this
0 commit comments