-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
v1.15 and type inference is still poor in Dart #26110
Comments
I think it's great that you report the issue. To be able to trust type inference is something I'm really looking forward to as well (also since a few years already ;-) ). Scala is almost 10 years older and therefore had 10 more years to be refined. There was lot of progress made the past months improving the analyzer. |
To decode your example for others: the Analyzer complains about Example: https://dartpad.dartlang.org/634ca4a8a4e61650a56c I think this is a duplicate of #18864 ("Add hint for incorrect assignment based on propagated types") |
I think the real issue here is the tension between optional typing and mandatory typing. When the spec says (version 1.11, p.16) that In contrast, languages like Scala require complete typing, and they will only allow for omitting type annotations when the context allows the type annotations to be inferred. With that approach, So we are really considering a request for a different style of type system, not just a set of bug fixes. The analyzer tries to deliver such a different style of static analysis via hints, based on local data flow analysis. But the hints do not rely on an explicitly and completely specified type system---there is no explicit specification of exactly which kind of flow analysis it should use, and results produced using flow analysis may not in general correspond directly to any "normal" type system. For instance, a flow analysis could conclude that Maybe a good resolution of this issue is the same thing as creating an explicitly and completely specified type system with inference? |
Actually, that's exactly what strong mode is intended to be. @MikeMitterer Have you tried enabling strong mode to see whether it does what you want? If not, create a file named
It might do more than you like, though. Strong mode defines a sound type system, which has lots of other implications. See https://github.com/dart-lang/dev_compiler/blob/master/STRONG_MODE.md for more information. |
Thanks for the feedback! Yes @bwilkerson I've tried the strong mode a few month ago. I found it a bit too strong. It even warned me if "super" was the first call in the initializer list (should be the last call). The problem is that all my inherited classes follow this pattern ': super(var), all other vars {' I got x-pages full of warnings? errors? can't remember but it was way too much... Ok - I just turned it on again to show you what I mean:
Hmmm - so no solution for this. I gona turn strong mode off again... +1 @eernstg For a completely specified type system. Quite a while ago I asked in G+/Dartisans who's using type annotations: (https://goo.gl/XpdOPZ) 83% are using strong types. (13% said they use strong types mostly) |
@vsmenon for the feedback on strong mode. |
@MikeMitterer the popup in your example is complaining about the parameter type, not the return type. We could make our errors clearer in that regard. Regarding super-at-end, if our tools automatically fixed that for you (e.g., an IDE-based autofix), would that work for you? |
Note that with a .analysis_options file you can opt out of entire classes of warnings that you don't care about. @pq could probably tell you what to put to turn off the super warning. |
@vsmenon Really??? Which parameter type - I thought it is complaining that listen is declared as listen(void callback(...)...) but the callback is defined as closure and this closure has a dynamic return type... Yes - the super-at-end thing should be either fixed by the IDE or even better the compiler should handle that. It looks strange to me it the last thing in the initializer-list is "super". In other languages it's either common or recommend to call the super-constructor first and then do the other stuff - should be the same in Dart too. |
About the return types of function expressions (lambdas): It's often very .. xs.map((T t) => expr) .. then becomes S goodName(T t) => expr; where the On Thu, Mar 31, 2016 at 2:01 AM, Leaf Petersen notifications@github.com
Erik Ernst - Google Danmark ApS |
I think this is only where super is called in the constructor body and there it's important that super() is executed before That super() should be last within the initialization list is a different thing. |
Hmmm - I know what super does... what I tried to explain is that it should be part of the compilation process to make sure that everything that is in the initializer list is called in the right order. To me this is the main reason why Dart has an initializer-list. (like in C++). This initializer-list makes sure that an object is properly setup if we call other functions in it's CTOR. BTW: @eernstg Because we are talking about Analyzer. I've just changed the interface of one of my proxy-classes and I gave Analyzer a shot. After so many years of Dart - I still don't get it why these "warnings" and "hints" ARE warnings or hints. These are errors! If I call a function with a wrong type or a wrong number of positional arguments it's likely that my application crashes. If a call could crash the application it should (must...) be treated as error. Maybe this is not well defined in the specs or whatever but as said I haven't seen any other major language that treats such things so liberal (or if so you can turn on a "strict mode"). (OK - forget JS - everything is possible in JS but that's a reason not to use JS!) |
About hints/warnings/errors: You might prefer very strict checks It does matter, though. For Dart, it was considered important to let The hints provide additional information about likely runtime type errors If you want to make sure that there are no warnings or hints, just check In short, this design allows you to hunt down all these apparently faulty On Thu, Mar 31, 2016 at 11:09 AM, Mike Mitterer notifications@github.com
Erik Ernst - Google Danmark ApS |
@MikeMitterer I was looking at the very end of the popup message. It says:
Your closure expects an Regarding https://github.com/dart-lang/linter/blob/master/lib/src/rules/super_goes_last.dart |
Strong mode will allow a |
I think all of this is addressed now in strong mode, let me know if there's something else we should file a specific issue for. (Covariant parameter overrides are covered under: #25578) |
From time to time I try to declare variables right side only just to figure out if it finally works but it still fails! (After how many years of Dart??? 3? 4?)
In your styleguide you promote this kind of declaration (https://www.dartlang.org/effective-dart/style/#prefer-using-lowercamelcase-for-constant-names) which is cool if it would work. And yes - in some situations it works but it fails in other cases. Maybe you guys know all these cases but I don't.
There is always this feeling that type inference fails in Dart and that I have to define the types on both sides to make sure that Analyzer knows what I mean.
The same thing for Generics.
final List<String> name = new List<String>()
this is how a String-List looks in my code. I'm almost!!!! sure that for the assignmentnew List()
is enough but I'm always a bit leery if the analyzer / autocompletion in IJ always knows what I mean so I use the long form.Very annoying - Dart is such a nice language but here it really falls behind other languages like Scala.
The text was updated successfully, but these errors were encountered: