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
Completer doesn't respect generic type... #20108
Comments
Added Area-Library, Library-Async, Triaged labels. |
The compiler, sadly, has to accept it. If it also gets through at runtime, in checked mode, then we should add an extra type assertion somewhere. |
This comment was originally written by @Emasoft I don't understand why it cannot be done. if(generic_class is instanced for type T) ? |
The problem is that the signature of Completer<T>.complete is "dynamic->void". There is nothing in that type that allows the compiler to reject an integer argument, and nothing in the specification that special-cases completers, so the analyzer is not allowed to give a warning (warnings are restricted to the warnings specified by the language specification). The compiler cannot stop you from doing this, because there is no way to tell the compiler that it is wrong. If you run the code in checked mode, it will fail with a TypeError. The best thing we can do is to let the analyzer have a special case for completers, so that it can give a hint if you pass a non-S and non-Future<S> to Completer<S>.complete. Removed Type-Defect, Area-Library labels. |
This comment was originally written by @Emasoft If it can give an hint, it can also give an error, right? And it should do, so it will spare us from a billion bugs just waiting to happen. |
We make a strong distinction between the words "error", "warning" and "hint". Probably stronger than you care about. So, yes, we can produce an error (in the generic sense) for this case. Removed Priority-Unassigned label. |
This comment was originally written by @Emasoft Then you should. Related to: |
This comment was originally written by adrian.avil...@gmail.com Honestly, I simple warning would be nice. |
This is fixed by Dart2+ |
This issue was originally filed by adrian.avil...@gmail.com
.complete<T> should be match Completer<T> and disallow any other type.
What steps will reproduce the problem?
Completer<String> pCompleter = new Completer<String>();
pCompleter.complete(123); //<-- This should be an error but the compiler permits it.
What is the expected output? What do you see instead?
An error from the compiler
What version of the product are you using?
Dart 1.5.3
On what operating system?
Windows 8.1
The text was updated successfully, but these errors were encountered: