Skip to content

improve strong mode inference error messages #29108

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

Closed
jmesserly opened this issue Mar 17, 2017 · 4 comments
Closed

improve strong mode inference error messages #29108

jmesserly opened this issue Mar 17, 2017 · 4 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Milestone

Comments

@jmesserly
Copy link

from @leafpetersen

The original error message is from this code:

values.fold(values.elementAt(0) as num, math.max)

The original error message is this:

[error] Couldn't infer type parameter 'T'.

Inferred type 'num' does not work with constraints:
  Argument 'combine' inferred as '(dynamic, dynamic) → dynamic' must be a '(T, dynamic) → T'.
The type 'num' was inferred from:
  Return type             declared as 'T'   used where a 'num' is required.
  Argument 'initialValue' inferred as 'num' must be a 'T'.

I ended up with this:

The type parameter 'T' was inferred to be 'num'
  Therefore argument 'combine' should be '(num, dynamic) → num', but
   the inferred type for 'combine' is '(dynamic, dynamic) → dynamic'.
The type 'num' was inferred for 'T' because:
  Return type             declared as 'T'   used where a 'num' is expected.

The changes are:

  • partially just wording: trying to avoid just saying things like "must be" or "is required', and instead try to give some intuition.
  • partially using the instantiated rather than uninstantiated type when talking about why the inference failed
  • In this case eliding the upwards constraints, which I think will be irrelevant with your new CL changes.
@jmesserly jmesserly self-assigned this Mar 18, 2017
@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Mar 20, 2017
@jmesserly jmesserly added this to the 1.23 milestone Mar 20, 2017
@jmesserly
Copy link
Author

I think we'd like to get this in 1.23 as it will improve usability of the error messages. (So, a really good tradeoff in terms of effort to user happiness.)

@bwilkerson
Copy link
Member

That would be great, but at this point the question might be: is it essential that this happen for 1.23 (that is, should we hold up the release because of this). From that perspective, I'd remove the milestone.

@jmesserly
Copy link
Author

yes. I will do it today, so hopefully this point becomes moot.

@jmesserly
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants