@@ -712,48 +712,44 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
712
712
current->getName (),
713
713
otherInit->isMemberwiseInitializer ());
714
714
} else if (current->isImplicit () || other->isImplicit ()) {
715
- // If both declarations are implicit, we diagnose the nearest
716
- // non-implicit DC because it is likely that we do not have a
717
- // valid source location for the declaration and we want to
718
- // avoid emitting it at an unknown location .
715
+ // If both declarations are implicit, we do not diagnose anything
716
+ // as it would lead to misleading diagnostics and it's likely that
717
+ // there's nothing actionable about it due to its implicit nature.
718
+ // One special case for this is property wrappers .
719
719
//
720
720
// Otherwise, if 'current' is implicit, then we diagnose 'other'
721
721
// since 'other' is a redeclaration of 'current'. Similarly, if
722
722
// 'other' is implicit, we diagnose 'current'.
723
- const auto *declToDiagnose = currentDC-> getAsDecl () ;
723
+ const Decl *declToDiagnose = nullptr ;
724
724
if (current->isImplicit () && other->isImplicit ()) {
725
725
// If 'current' is a property wrapper backing storage property
726
726
// or projected value property, then diagnose the wrapped
727
- // property instead of the nearest non-implicit DC .
727
+ // property.
728
728
if (auto VD = dyn_cast<VarDecl>(current)) {
729
729
if (auto originalWrappedProperty =
730
730
VD->getOriginalWrappedProperty ()) {
731
731
declToDiagnose = originalWrappedProperty;
732
732
}
733
- } else {
734
- // Get the nearest non-implicit decl context
735
- while (declToDiagnose && declToDiagnose->isImplicit () &&
736
- declToDiagnose->getDeclContext ()) {
737
- declToDiagnose = declToDiagnose->getDeclContext ()->getAsDecl ();
738
- }
739
733
}
740
734
} else {
741
735
declToDiagnose = current->isImplicit () ? other : current;
742
736
}
743
737
744
- // Figure out if the the declaration we've redeclared is a synthesized
745
- // witness for a protocol requirement.
746
- bool isProtocolRequirement = false ;
747
- if (auto VD = dyn_cast<ValueDecl>(current->isImplicit () ? current
748
- : other)) {
749
- isProtocolRequirement = llvm::any_of (
750
- VD->getSatisfiedProtocolRequirements (), [&](ValueDecl *req) {
751
- return req->getName () == VD->getName ();
752
- });
738
+ if (declToDiagnose) {
739
+ // Figure out if the the declaration we've redeclared is a
740
+ // synthesized witness for a protocol requirement.
741
+ bool isProtocolRequirement = false ;
742
+ if (auto VD = dyn_cast<ValueDecl>(current->isImplicit () ? current
743
+ : other)) {
744
+ isProtocolRequirement = llvm::any_of (
745
+ VD->getSatisfiedProtocolRequirements (), [&](ValueDecl *req) {
746
+ return req->getName () == VD->getName ();
747
+ });
748
+ }
749
+ declToDiagnose->diagnose (diag::invalid_redecl_implicit,
750
+ current->getDescriptiveKind (),
751
+ isProtocolRequirement, other->getName ());
753
752
}
754
- declToDiagnose->diagnose (diag::invalid_redecl_implicit,
755
- current->getDescriptiveKind (),
756
- isProtocolRequirement, other->getName ());
757
753
758
754
// Emit a specialized note if the one of the declarations is
759
755
// the backing storage property ('_foo') or projected value
0 commit comments