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

Enhancement for dartanalyzer: Emit hints for special case of function type compatibility checking #2135

Open
mkustermann opened this issue Jun 19, 2014 · 4 comments
Labels
lint-request type-enhancement A request for a change that isn't a bug

Comments

@mkustermann
Copy link
Member

The following code does not emit a dartanalyzer error/warning/hint

import 'dart:async';

typedef void VoidReturnType(String msg);

bar(VoidReturnType function, String msg) {
  function(msg);
}

main() {
  Future fun(String m) {
    print(m);
    // The future returned here could come from other parts of the program.
    return new Future.error('unexpected error');
  }

  bar(fun, 'hello world');
}

Reading the dart specification, this seems correct behavior:

A function type (T1, ..., Tk, ...) → T is a subtype of the function type (S1, ..., Sk+j, ...) → S, if all of the following conditions are met:
Either
  S is void,
  or T ⇔ S.

But it can cause easily programming errors, where

  • programmer A assumes that the caller will handle the returned Future
  • programmer B who does something with the function, assumes it is void

I think this is a case where type systems usually helps users, but not in the case of the dart type system.
It would be very beneficial for our users to get at least a hint in this specific case.

More broadly speaking, it would be beneficial to get hints if a user doesn't act upon a future object it gets from somewhere (neither handles it's value nor it's errors).

@bwilkerson
Copy link
Member

Added this to the Later milestone.
Removed Priority-Unassigned label.
Added Priority-Medium, Analyzer-Hint labels.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@srawlins srawlins transferred this issue from dart-lang/sdk Jun 8, 2020
@srawlins
Copy link
Member

srawlins commented Jun 8, 2020

Since the analyzer is going by the spec, and the request is for additional, false-positive-prone analysis, I think this would be a good one for the linter.

@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants