Open
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
pq commentedon Nov 13, 2018
From @stereotype441 on November 13, 2018 23:44
@pq should this bug be moved into the linter repo?
Type
#35144eernstg commentedon 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.