Skip to content

Commit 898346f

Browse files
committed
[CSFix] Add a fix to add a missing qualifier to shadowed top-level name references
1 parent 1fff12f commit 898346f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/CSFix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,13 @@ SpecifyObjectLiteralTypeImport::create(ConstraintSystem &cs,
11801180
ConstraintLocator *locator) {
11811181
return new (cs.getAllocator()) SpecifyObjectLiteralTypeImport(cs, locator);
11821182
}
1183+
1184+
bool AddQualifierToAccessTopLevelName::diagnose(bool asNote) const {
1185+
return false;
1186+
}
1187+
1188+
AddQualifierToAccessTopLevelName *
1189+
AddQualifierToAccessTopLevelName::create(ConstraintSystem &cs,
1190+
ConstraintLocator *locator) {
1191+
return new (cs.getAllocator()) AddQualifierToAccessTopLevelName(cs, locator);
1192+
}

lib/Sema/CSFix.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ enum class FixKind : uint8_t {
235235
/// Closure return type has to be explicitly specified because it can't be
236236
/// inferred in current context e.g. because it's a multi-statement closure.
237237
SpecifyClosureReturnType,
238-
238+
239239
/// Object literal type coudn't be infered because the module where
240240
/// the default type that implements the associated literal protocol
241241
/// is declared was not imported.
242242
SpecifyObjectLiteralTypeImport,
243243

244+
/// Member shadows a top-level name, such a name could only be accessed by
245+
/// prefixing it with a module name.
246+
AddQualifierToAccessTopLevelName,
244247
};
245248

246249
class ConstraintFix {
@@ -1652,7 +1655,22 @@ class SpecifyObjectLiteralTypeImport final : public ConstraintFix {
16521655

16531656
static SpecifyObjectLiteralTypeImport *create(ConstraintSystem &cs,
16541657
ConstraintLocator *locator);
1658+
};
1659+
1660+
class AddQualifierToAccessTopLevelName final : public ConstraintFix {
1661+
AddQualifierToAccessTopLevelName(ConstraintSystem &cs,
1662+
ConstraintLocator *locator)
1663+
: ConstraintFix(cs, FixKind::AddQualifierToAccessTopLevelName, locator) {}
1664+
1665+
public:
1666+
std::string getName() const {
1667+
return "qualify reference to access top-level function";
1668+
}
16551669

1670+
bool diagnose(bool asNote = false) const;
1671+
1672+
static AddQualifierToAccessTopLevelName *create(ConstraintSystem &cs,
1673+
ConstraintLocator *locator);
16561674
};
16571675

16581676
} // end namespace constraints

0 commit comments

Comments
 (0)