-
Notifications
You must be signed in to change notification settings - Fork 7.9k
GH-15994: fix suggestion that anonymous classes be made abstract #15995
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
Conversation
The first commit is already sent at #15993, but to avoid merge conflicts I sent this as a follow-up to that patch - marking this as a draft until that merges |
In the process, remove the (incorrect) assumption that any abstract method that needs to be implemented by a class that cannot itself be made abstract must be a private method - the existing test for an enum already showed that this was not the case.
ffd08b6
to
6fe1152
Compare
@iluuu1994 would you mind taking a look? This is a follow-up to #15993 |
Zend/tests/anon/gh15994.phpt
Outdated
|
||
$c = new class { | ||
abstract public function f(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this message doesn't make too much sense to me, as we cannot implement a method that is also declared as abstract. Maybe we should disallow abstract
functions in anonymous classes in the compiler. This message would still make sense when the method comes from a parent class, interface or trait.
Granted, that is not really related to this change, so I'm happy if you move the abstract method to a parent class.
In reality, we should probably also change the error message for this:
class Foo {
public abstract function bar();
}
Fatal error: Class Foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Foo::bar)
Implementing Foo::bar()
is a weird suggestion, given the abstract declaration comes from this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should disallow abstract functions in anonymous classes in the compiler.
I can work on a patch for that
I'm happy if you move the abstract method to a parent class.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'll merge as soon as tests have passed 🙂
Thank you! |
In the process, remove the (incorrect) assumption that any abstract method that
needs to be implemented by a class that cannot itself be made abstract must be
a private method - the existing test for an enum already showed that this was
not the case.