mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add a Fixit to Rewrite NSObject.hash(into:) Overrides
This commit is contained in:
@@ -1012,10 +1012,12 @@ static void checkOverrideAccessControl(ValueDecl *baseDecl, ValueDecl *decl,
|
|||||||
// NSObject.hashValue and NSObject.hash(into:) are not overridable;
|
// NSObject.hashValue and NSObject.hash(into:) are not overridable;
|
||||||
// one should override NSObject.hash instead.
|
// one should override NSObject.hash instead.
|
||||||
if (isNSObjectHashValue(baseDecl)) {
|
if (isNSObjectHashValue(baseDecl)) {
|
||||||
diags.diagnose(decl, diag::override_nsobject_hashvalue_error)
|
decl->diagnose(diag::override_nsobject_hashvalue_error)
|
||||||
.fixItReplace(SourceRange(decl->getNameLoc()), "hash");
|
.fixItReplace(SourceRange(decl->getNameLoc()), "hash");
|
||||||
} else if (isNSObjectHashMethod(baseDecl)) {
|
} else if (isNSObjectHashMethod(baseDecl)) {
|
||||||
diags.diagnose(decl, diag::override_nsobject_hash_error);
|
decl->diagnose(diag::override_nsobject_hash_error)
|
||||||
|
.fixItReplace(cast<FuncDecl>(decl)->getFuncLoc(), getTokenText(tok::kw_var))
|
||||||
|
.fixItReplace(cast<FuncDecl>(decl)->getParameters()->getSourceRange(), ": Int");
|
||||||
} else {
|
} else {
|
||||||
diags.diagnose(decl, diag::override_of_non_open,
|
diags.diagnose(decl, diag::override_of_non_open,
|
||||||
decl->getDescriptiveKind());
|
decl->getDescriptiveKind());
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ extension NSObject : Equatable, Hashable {
|
|||||||
///
|
///
|
||||||
/// NSObject implements this by feeding `self.hash` to the hasher.
|
/// NSObject implements this by feeding `self.hash` to the hasher.
|
||||||
///
|
///
|
||||||
/// 'NSObject.hash(into:)' is not overridable; subclasses can customize
|
/// `NSObject.hash(into:)` is not overridable; subclasses can customize
|
||||||
/// hashing by overriding the `hash` property.
|
/// hashing by overriding the `hash` property.
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
hasher.combine(self.hash)
|
hasher.combine(self.hash)
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ class MyHashableNSObject: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func hash(into hasher: inout Hasher) {
|
override func hash(into hasher: inout Hasher) {
|
||||||
// expected-error@-1 {{'NSObject.hash(into:)' is not overridable; did you mean to override 'NSObject.hash'?}}
|
// expected-error@-1 {{'NSObject.hash(into:)' is not overridable; did you mean to override 'NSObject.hash'?}} {{12-16=var}} {{21-48=: Int}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ class Foo: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func hash(into hasher: inout Hasher) {
|
override func hash(into hasher: inout Hasher) {
|
||||||
// expected-error@-1 {{'NSObject.hash(into:)' is not overridable; did you mean to override 'NSObject.hash'?}}
|
// expected-error@-1 {{'NSObject.hash(into:)' is not overridable; did you mean to override 'NSObject.hash'?}} {{12-16=var}} {{21-48=: Int}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user