Skip to content

Commit 7351bfc

Browse files
committed
[CSFix] Add a fix to add a missing qualifier to shadowed top-level name references
1 parent ffa6bf4 commit 7351bfc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Sema/CSFix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,3 +1217,13 @@ AllowNonClassTypeToConvertToAnyObject::create(ConstraintSystem &cs, Type type,
12171217
return new (cs.getAllocator())
12181218
AllowNonClassTypeToConvertToAnyObject(cs, type, locator);
12191219
}
1220+
1221+
bool AddQualifierToAccessTopLevelName::diagnose(bool asNote) const {
1222+
return false;
1223+
}
1224+
1225+
AddQualifierToAccessTopLevelName *
1226+
AddQualifierToAccessTopLevelName::create(ConstraintSystem &cs,
1227+
ConstraintLocator *locator) {
1228+
return new (cs.getAllocator()) AddQualifierToAccessTopLevelName(cs, locator);
1229+
}

lib/Sema/CSFix.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ enum class FixKind : uint8_t {
244244
/// Allow any type (and not just class or class-constrained type) to
245245
/// be convertible to AnyObject.
246246
AllowNonClassTypeToConvertToAnyObject,
247+
248+
/// Member shadows a top-level name, such a name could only be accessed by
249+
/// prefixing it with a module name.
250+
AddQualifierToAccessTopLevelName,
247251
};
248252

249253
class ConstraintFix {
@@ -1655,7 +1659,22 @@ class SpecifyObjectLiteralTypeImport final : public ConstraintFix {
16551659

16561660
static SpecifyObjectLiteralTypeImport *create(ConstraintSystem &cs,
16571661
ConstraintLocator *locator);
1662+
};
1663+
1664+
class AddQualifierToAccessTopLevelName final : public ConstraintFix {
1665+
AddQualifierToAccessTopLevelName(ConstraintSystem &cs,
1666+
ConstraintLocator *locator)
1667+
: ConstraintFix(cs, FixKind::AddQualifierToAccessTopLevelName, locator) {}
1668+
1669+
public:
1670+
std::string getName() const {
1671+
return "qualify reference to access top-level function";
1672+
}
16581673

1674+
bool diagnose(bool asNote = false) const;
1675+
1676+
static AddQualifierToAccessTopLevelName *create(ConstraintSystem &cs,
1677+
ConstraintLocator *locator);
16591678
};
16601679

16611680
class AllowNonClassTypeToConvertToAnyObject final : public ContextualMismatch {

0 commit comments

Comments
 (0)