@@ -4733,35 +4733,24 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4733
4733
// Check for static/final/class when we're in a type.
4734
4734
auto dc = FD->getDeclContext ();
4735
4735
if (dc->isTypeContext ()) {
4736
- // Within a class, operator functions must be 'static' or 'final'.
4737
- if (auto classDecl = dc->getAsClassOrClassExtensionContext ()) {
4738
- // For a class, we also need the function or class to be 'final'.
4739
- if (!classDecl->isFinal () && !FD->isFinal () &&
4740
- FD->getStaticSpelling () != StaticSpellingKind::KeywordStatic) {
4741
- if (!FD->isStatic ()) {
4742
- TC.diagnose (FD->getLoc (), diag::nonstatic_operator_in_type,
4743
- operatorName,
4744
- dc->getDeclaredInterfaceType ())
4745
- .fixItInsert (FD->getAttributeInsertionLoc (/* forModifier=*/ true ),
4746
- " static " );
4747
-
4748
- FD->setStatic ();
4749
- } else {
4750
- TC.diagnose (FD->getLoc (), diag::nonfinal_operator_in_class,
4751
- operatorName, dc->getDeclaredInterfaceType ())
4752
- .fixItInsert (FD->getAttributeInsertionLoc (/* forModifier=*/ true ),
4753
- " final " );
4754
- FD->getAttrs ().add (new (TC.Context ) FinalAttr (/* IsImplicit=*/ true ));
4755
- }
4756
- }
4757
- } else if (!FD->isStatic ()) {
4758
- // Operator functions must be static.
4759
- TC.diagnose (FD, diag::nonstatic_operator_in_type,
4736
+ if (!FD->isStatic ()) {
4737
+ TC.diagnose (FD->getLoc (), diag::nonstatic_operator_in_type,
4760
4738
operatorName,
4761
4739
dc->getDeclaredInterfaceType ())
4762
4740
.fixItInsert (FD->getAttributeInsertionLoc (/* forModifier=*/ true ),
4763
4741
" static " );
4742
+
4764
4743
FD->setStatic ();
4744
+ } else if (auto classDecl = dc->getAsClassOrClassExtensionContext ()) {
4745
+ // For a class, we also need the function or class to be 'final'.
4746
+ if (!classDecl->isFinal () && !FD->isFinal () &&
4747
+ FD->getStaticSpelling () != StaticSpellingKind::KeywordStatic) {
4748
+ TC.diagnose (FD->getLoc (), diag::nonfinal_operator_in_class,
4749
+ operatorName, dc->getDeclaredInterfaceType ())
4750
+ .fixItInsert (FD->getAttributeInsertionLoc (/* forModifier=*/ true ),
4751
+ " final " );
4752
+ FD->getAttrs ().add (new (TC.Context ) FinalAttr (/* IsImplicit=*/ true ));
4753
+ }
4765
4754
}
4766
4755
} else if (!dc->isModuleScopeContext ()) {
4767
4756
TC.diagnose (FD, diag::operator_in_local_scope);
0 commit comments