Skip to content

[Type checker] Extend redundant-conformance warning to imported types. #9507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6101,13 +6101,15 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
auto extendedNominal =
diag.ExistingDC->getAsNominalTypeOrNominalTypeExtensionContext();
if (existingModule != dc->getParentModule() &&
(existingModule == extendedNominal->getParentModule() ||
(existingModule->getName() ==
extendedNominal->getParentModule()->getName() ||
existingModule == diag.Protocol->getParentModule())) {
// Warn about the conformance.
diagnose(diag.Loc, diag::redundant_conformance_adhoc,
dc->getDeclaredInterfaceType(),
diag.Protocol->getName(),
existingModule == extendedNominal->getParentModule(),
existingModule->getName() ==
extendedNominal->getParentModule()->getName(),
existingModule->getName());

// Complain about any declarations in this extension whose names match
Expand Down
9 changes: 9 additions & 0 deletions test/Compatibility/range_hashable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-typecheck-verify-swift -swift-version 3

// REQUIRES: objc_interop

import Foundation

extension NSRange : Hashable { // expected-warning{{conformance of '_NSRange' to protocol 'Hashable' was already stated in the type's module 'Foundation'}}
var hashValue: Int { return 0 } // expected-note{{var 'hashValue' will not be used to satisfy the conformance to 'Hashable'}}
}