Skip to content

Lint: Avoid using function types as a runtime Type #57827

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

Open
pq opened this issue Nov 13, 2018 · 2 comments
Open

Lint: Avoid using function types as a runtime Type #57827

pq opened this issue Nov 13, 2018 · 2 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented Nov 13, 2018

From @matanlurey on November 13, 2018 1:29

I don't know how this lint request will interact with the generalized typedef language proposals

In Dart 2.x, typedef relates directly to its structural type, and is not a "type" itself. Which means:

typedef A = void Function();
typedef B = void Function();
void main() {
  var set = Set();
  set.add(A);
  set.add(B);
  print(set.length); // 1
}

Due to the severe restrictions of using mirrors in any real code, treating a typedef definition as a runtime Type is not useful in anyway, and can be very confusing/error prone to users (see above). There is some resistance to amending the style guide (dart-lang/site-www#1221), which I think is on point - so instead I opened this request.

With this lint, you'd see:

typedef A = void Function();
typedef B = void Function();
void main() {
  var set = Set();
  // LINT:
  set.add(A);
  //            ^
  // LINT: AVOID using a typedef or function type as a runtime type literal.
  set.add(B);
  //            ^
  // LINT: AVOID using a typedef or function type as a runtime type literal.
  print(set.length); // 1
}

I don't see any real downsides to this lint.

/cc @natebosch @munificent @leafpetersen @srawlins

Copied from original issue: #35144

@pq pq added the P2 A bug or feature request we're likely to work on label Nov 13, 2018
@pq
Copy link
Member Author

pq commented Nov 13, 2018

From @stereotype441 on November 13, 2018 23:44

@pq should this bug be moved into the linter repo?

@eernstg
Copy link
Member

eernstg commented Nov 16, 2018

Interesting! This seems to be related to another topic that we've discussed from time to time, namely branded types. Here's a proposal for some support in that direction, with some remarks near the end about why it is related to this issue: #57828.

@srawlins srawlins added the P3 A lower priority bug or feature request label Oct 11, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants