Skip to content

Commit e51c883

Browse files
jrose-appletkremenek
authored andcommitted
Provide fix-its when overriding a bridged value type with the old reference type (#2479) (#2753)
Merge pull request #2479 from jrose-apple/override-value-types-fix-it (cherry picked from commit 55a97dd)
1 parent 4afe0c6 commit e51c883

File tree

19 files changed

+342
-26
lines changed

19 files changed

+342
-26
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,8 @@ class VarDecl : public AbstractStorageDecl {
41904190
return VarDeclBits.IsUserAccessible;
41914191
}
41924192

4193-
/// \brief Retrieve the source range of the variable type.
4193+
/// Retrieve the source range of the variable type, or an invalid range if the
4194+
/// variable's type is not explicitly written in the source.
41944195
///
41954196
/// Only for use in diagnostics. It is not always possible to always
41964197
/// precisely point to the variable type because of type aliases.

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,12 @@ NOTE(subscript_override_here,none,
14581458
"attempt to override subscript here", ())
14591459
NOTE(convenience_init_override_here,none,
14601460
"attempt to override convenience initializer here", ())
1461+
NOTE(override_type_mismatch_with_fixits,none,
1462+
"type does not match superclass %0 with type %1",
1463+
(DescriptiveDeclKind, Type))
1464+
NOTE(override_type_mismatch_with_fixits_init,none,
1465+
"type does not match superclass initializer with %select{no arguments|argument %1|arguments %1}0",
1466+
(unsigned, Type))
14611467
ERROR(override_nonclass_decl,none,
14621468
"'override' can only be specified on class members", ())
14631469
ERROR(override_property_type_mismatch,none,

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ IDENTIFIER_(nsErrorDomain)
5151
IDENTIFIER(objectAtIndexedSubscript)
5252
IDENTIFIER(objectForKeyedSubscript)
5353
IDENTIFIER(ObjectiveC)
54+
IDENTIFIER_(ObjectiveCType)
5455
IDENTIFIER_(OptionalNilComparisonType)
5556
IDENTIFIER(parameter)
5657
IDENTIFIER(Protocol)

include/swift/Basic/SourceLoc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class SourceRange {
9696
bool isValid() const { return Start.isValid(); }
9797
bool isInvalid() const { return !isValid(); }
9898

99+
bool operator==(const SourceRange &other) const {
100+
return Start == other.Start && End == other.End;
101+
}
102+
bool operator!=(const SourceRange &other) const { return !operator==(other); }
103+
99104
/// Print out the SourceRange. If the locations are in the same buffer
100105
/// as specified by LastBufferID, then we don't print the filename. If not,
101106
/// we do print the filename, and then update LastBufferID with the BufferID
@@ -134,6 +139,13 @@ class CharSourceRange {
134139
bool isValid() const { return Start.isValid(); }
135140
bool isInvalid() const { return !isValid(); }
136141

142+
bool operator==(const CharSourceRange &other) const {
143+
return Start == other.Start && ByteLength == other.ByteLength;
144+
}
145+
bool operator!=(const CharSourceRange &other) const {
146+
return !operator==(other);
147+
}
148+
137149
SourceLoc getStart() const { return Start; }
138150
SourceLoc getEnd() const { return Start.getAdvancedLocOrInvalid(ByteLength); }
139151

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,9 +3987,9 @@ ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
39873987

39883988
// Find the type we bridge to.
39893989
return ProtocolConformance::getTypeWitnessByName(type,
3990-
conformance->getConcrete(),
3991-
getIdentifier("_ObjectiveCType"),
3992-
resolver);
3990+
conformance->getConcrete(),
3991+
Id_ObjectiveCType,
3992+
resolver);
39933993
}
39943994

39953995
std::pair<ArchetypeBuilder *, ArchetypeBuilder::PotentialArchetype *>

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,14 +2746,6 @@ struct ASTNodeBase {};
27462746
}
27472747
checkSourceRanges(D->getSourceRange(), Parent,
27482748
[&]{ D->print(Out); });
2749-
if (auto *VD = dyn_cast<VarDecl>(D)) {
2750-
if (!VD->getTypeSourceRangeForDiagnostics().isValid()) {
2751-
Out << "invalid type source range for variable decl: ";
2752-
D->print(Out);
2753-
Out << "\n";
2754-
abort();
2755-
}
2756-
}
27572749
}
27582750

27592751
/// \brief Verify that the given source ranges is contained within the

lib/AST/Decl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3369,13 +3369,14 @@ SourceRange VarDecl::getTypeSourceRangeForDiagnostics() const {
33693369

33703370
Pattern *Pat = getParentPattern();
33713371
if (!Pat || Pat->isImplicit())
3372-
return getSourceRange();
3372+
return SourceRange();
33733373

33743374
if (auto *VP = dyn_cast<VarPattern>(Pat))
33753375
Pat = VP->getSubPattern();
33763376
if (auto *TP = dyn_cast<TypedPattern>(Pat))
33773377
return TP->getTypeLoc().getTypeRepr()->getSourceRange();
3378-
return getSourceRange();
3378+
3379+
return SourceRange();
33793380
}
33803381

33813382
static bool isVarInPattern(const VarDecl *VD, Pattern *P) {

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
807807
Type objcType = ProtocolConformance::getTypeWitnessByName(
808808
nominal->getDeclaredType(),
809809
conformance,
810-
ctx.getIdentifier("_ObjectiveCType"),
810+
ctx.Id_ObjectiveCType,
811811
nullptr);
812812
if (!objcType) return false;
813813

lib/SIL/Bridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
216216
assert(conformance && "Missing conformance?");
217217
Type bridgedTy =
218218
ProtocolConformance::getTypeWitnessByName(
219-
t, conformance, M.getASTContext().getIdentifier("_ObjectiveCType"),
219+
t, conformance, M.getASTContext().Id_ObjectiveCType,
220220
nullptr);
221221
assert(bridgedTy && "Missing _ObjectiveCType witness?");
222222
if (bridgedCollectionsAreOptional && clangTy)

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ SILGenModule::getBridgedObjectiveCTypeRequirement(SILLocation loc) {
241241
// Look for _bridgeToObjectiveC().
242242
auto &ctx = getASTContext();
243243
AssociatedTypeDecl *found = nullptr;
244-
DeclName name(ctx.getIdentifier("_ObjectiveCType"));
244+
DeclName name(ctx.Id_ObjectiveCType);
245245
for (auto member : proto->lookupDirect(name, true)) {
246246
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
247247
found = assocType;

0 commit comments

Comments
 (0)