dart-lang / dart-lang/language

Infer generic type parameters based on the declaring type

Open
#620 31 comments 90 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

cross reference : https://github.com/felangel/bloc/issues/560

currently in dart, we have to explicitly specify a type parameter for generic types, even when they can be inferred.
e.g. this is a valid class definition
```dart
class Bloc {}
class BlocBuilder,TState> {}

class TestBloc extends Bloc {}
class TestBlocBuilder extends BlocBuilder {}
```

but this isn't
```dart
class Bloc {}
class BlocBuilder> {}

class TestBloc extends Bloc {}
class TestBlocBuilder extends BlocBuilder {}
```
you get an error at BlocBuilder definition:
```
The name 'TState' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'TState'.
```

I am not sure if this is an intentional design choice, or a bug that no one noticed, but i sure hope this gets fixed.

Contributor guide

Open the contributing guide

Research direction

Start by reading the cross-reference at felangel/bloc#560 and the examples in this issue, then investigate Dart's generic type-parameter inference and declaring-type rules. Done means reaching a language-design decision and specifying whether the omitted TState form is valid, including the resulting diagnostics and inference behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.