Skip to content
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

Would like a way to see the analyzer's inferred type. #472

Open
eseidel opened this issue Nov 26, 2016 · 8 comments
Open

Would like a way to see the analyzer's inferred type. #472

eseidel opened this issue Nov 26, 2016 · 8 comments

Comments

@eseidel
Copy link

eseidel commented Nov 26, 2016

I'm constantly fighting errors like:

message: 'Unsound implicit cast from dynamic to List<Foo>'
at: '28,22'
source: 'dart'

From things like:

 List<Foo> foos = yaml['foos'].map((YamlMap yamlFoo) {
      return fooFactory.fooByName(yamlFoo['name']);
    }).toList();

It would help if there was a key combination I could use to see what the inferred type was in each step of my call chain.

dynamic poisons your chained calls, as soon as you hit one, the rest of them end up dynamic, so figuring out which step in the chain ended up dynamic is what I'm trying to do. Maybe this is an analyzer issue?

@zoechi
Copy link

zoechi commented Nov 26, 2016

"Quick Documentation" in WebStorm/IDEA seems to provide that information

@eseidel
Copy link
Author

eseidel commented Nov 26, 2016

So that works for variables, but not for methods/accessors. Example:

Map<String, String> foo;
var bar = foo.values;

If you highlight bar and hit f1 you see a static type of Iterator<String>, however if you highlight values you don't. When you have a long chain of calls, it could be useful to see the inferred types along the way. At least I think that would have helped me in fighting these strong_mode errors.

@raju-bitter
Copy link

+1 Would be very useful, especially when reading through code you haven't written yourself.

@devoncarew
Copy link
Member

/cc @jwren and @leafpetersen, who've discussed something similar.

@leafpetersen
Copy link

This is something I'd really like us to support better in the IDE - I'm hoping we can spend some time on it next quarter.

@eseidel I'm surprised that you don't see a type for values in that example though. If I use Quick Documentation with the cursor on values for that example I see:

Signature: get Map.values() → Iterable<String>

which is using the inferred type. This doesn't work for general expressions, but it should be working for any method calls. This is especially useful for generic methods. With this example:

Map<String, String> foo;
var bar = foo.values.map((x) => x.length);

Quick Documentation on map will give me:

Signature: Iterable.map((String) → T f) → Iterable<T> 

Static type: ((String) → int) → Iterable<int>

which tells me that int is the inferred type argument that is being filled in for the generic parameter T to Iterable.map.

@devoncarew devoncarew modified the milestone: Backlog Dec 6, 2016
@pq
Copy link
Contributor

pq commented Mar 10, 2017

@leafpetersen : what's the current thinking on support like this?

@leafpetersen
Copy link

I talked to @stevemessick about this a bit earlier this year. We're both keen to do something with this, but my guess is that there are a lot of higher priority things in the queue right now.

@pq
Copy link
Contributor

pq commented Mar 10, 2017

Good deal. My thinking too. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants