Skip to content

Commit 2667d3d

Browse files
committed
[CSSimplify] Add omitted projection name label as valid argument label and consolidate all checks for argument and parameter label matches into new Param member function.
1 parent 9a4572e commit 2667d3d

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/swift/AST/Types.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,23 @@ class AnyFunctionType : public TypeBase {
28392839

28402840
bool hasInternalLabel() const { return !InternalLabel.empty(); }
28412841
Identifier getInternalLabel() const { return InternalLabel; }
2842+
2843+
/// Return true if argument name is valid and matches \c paramName.
2844+
///
2845+
/// The three tests to check if argument name is valid are:
2846+
/// 1. allow argument if it matches \c paramName,
2847+
/// 2. allow argument if $_ for omitted projected value label,
2848+
/// 3. allow argument if it matches \c paramName without its \c $ prefix.
2849+
bool matchParameterLabel(Identifier const &paramName) const {
2850+
auto argLabel = getLabel();
2851+
if (argLabel == paramName)
2852+
return true;
2853+
if ((argLabel.str() == "$_") && paramName.empty())
2854+
return true;
2855+
if (argLabel.hasDollarPrefix() && argLabel.str().drop_front() == paramName.str())
2856+
return true;
2857+
return false;
2858+
}
28422859

28432860
ParameterTypeFlags getParameterFlags() const { return Flags; }
28442861

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,10 @@ static bool matchCallArgumentsImpl(
291291
assert(argIdx != numArgs && "Must have a valid index to claim");
292292
assert(!claimedArgs[argIdx] && "Argument already claimed");
293293

294-
auto argLabel = args[argIdx].getLabel();
295294
if (!actualArgNames.empty()) {
296295
// We're recording argument names; record this one.
297296
actualArgNames[argIdx] = expectedName;
298-
} else if (argLabel != expectedName && !ignoreNameClash &&
299-
!(argLabel.str().startswith("$") &&
300-
argLabel.str().drop_front() == expectedName.str())) {
297+
} else if (!ignoreNameClash && !args[argIdx].matchParameterLabel(expectedName)) {
301298
// We have an argument name mismatch. Start recording argument names.
302299
actualArgNames.resize(numArgs);
303300

0 commit comments

Comments
 (0)