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
Add a metadata to define if warnings should appear or not when "noSuchMethod" is defined #6111
Comments
Removed Type-Defect label. |
Added this to the M3 milestone. |
Set owner to @bwilkerson. |
This comment was originally written by @a14n I tried to use that global option, but having a lot of code dealing with js-interop, Dart editor gives me too much warnings to keep that option on. But without that, I cannot check if only declared methods are called. I would really liked to use such a case-by-case handling. Please, don't wait too much to give us that feature. I hope "Milestone-Later" does not mean "Milestone-Never". (in the above code snippet, I should have used "implements" instead of "extends") |
Set owner to @jwren. |
dart2js is reporting these warnings too, so I think this is more of a language issue. Added C1 label. |
FWIW, the latest spec draft specifies the effect that a noSuchMethod declaration has on warnings. In particular, it does NOT sanction any wholesale suppression of warnings on uses of the type. What it does specify is that if a class implements same interface I, and a noSuchMethod declaration is present in the class (not inherited) then no warnings about missing members of I will be given. |
This comment was originally written by @a14n When I wrote this issue I was looking for a solution to control when the warnings should appear. An alternative solution could be to
What do you think ? |
Gilad - I got a question about your clarification above. Will these warnings be omitted also for subclasses of the class that implements I? To be more concrete, here is an example: abstract class I { class A implements I { class B extends A { I was expecting to have no warnings in this code, but in today's implementation we get warnings saying that B doesn't implement 'i1' and 'i2'. Another very similar situation where we get these extra warnings is when A is an abstract class (which is what my code looks like): abstract class I { abstract class A implements I { class B extends A { |
eek, we hit this in JS interop package. For an example of terrible of how terrible it is, see this: https://chromiumcodereview.appspot.com/23095010/diff/1/lib/polymer_element.dart |
Set owner to @gbracha. |
There is a plan to add an annotation to deal with this situation. It is is temporarily named @Proxy, but we'll codify it in a standardized way in not too long. |
The annotation is currently called "@Proxy". It will soon be in the core library. It should be specified for milestone 8 if possible. Removed this from the Later milestone. |
@Proxy takes care of class A in Siggi's example, but it does not take care of class B. I've had to deal with code where noSuchMethod is present in a base class, but has to be added to a subclass just to quite the warnings. In js-interop there's a MagicProxy base class that implements noSuchMethod, and it's used like this: class PersonProxy extends MagicProxy implements Person { Otherwise warnings about not implementing Person haunt us. The particularly ugly part of this is that i\the requirement to workaround the warnings leaks to users of a library that uses nSM in a base class, you can't just deal with it in a library and ease the pain for them, they have to add the boilerplate themselves. |
What Justin said. |
Sorry, but @proxy is supposed to take care of B. It is supposed to silence warnings about unimplemented methods, regardles sof noSuchMethod. class A is taken care of because of the separate rule about noSuchMethod. As Alexandre said, that is sometimes too broad a brush, but in my view, better too few warnings than too many. I this doesn't work as I say, we should file a bug against the analyzer. Tentative spec for this is: Let C be a concrete class that does not declare its own noSuchMethod() method and is not annotated with a metadata declaration of the form @proxy, where proxy is declared in dart:core. It is a static warning if the implicit interface of C includes an instance member m of type F and C does not declare or inherit a corresponding instance member m of type F ′ such that F ′ <: F . Added Accepted label. |
I'm sorry Gilad, I wasn't specific enough. The base class has a @proxy annotation, the subclass doesn't. Adding @proxy is certainly nicer than adding a noSuchMethod() though. |
I see. Well, you need to stick @proxy on each class. It does not effect subclasses. I think that is reasonable behavior. |
The discussion here sort of veered off from the original feature request.
Given that, we aren't planning to spend a lot of effort adding more features around |
This issue was originally filed by @a14n
When "noSuchMethod" is defined, no warning is displayed on an undefined method call.
It would be great if a metadata on "noSuchMethod" could be used to define if a warning should appear or not when method is not defined.
Here is a pattern I'd like to use where I really want a warning on an undefined method :
/// definition of all valid methods
abstract class _Api {
method1();
method2();
}
/// all valid method calls are implemented by noSuchMethod and the other ones generate warnings
class Api extends _Api {
@warnOnUndefinedMethod
noSuchMethod(method, args) {
// implementation for all methods
}
}
This way, I could declare all valid methods and implement them in a single method.
The text was updated successfully, but these errors were encountered: