dart-lang / dart-lang/language

Optional Generics?

Open
#1,387 7 comments 11 reactions 0 assignees View on GitHub
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

A problem with the current Generic implementation, is anytime you want to specify one type, you need to declare them all. This can lead to excessive typing and obfuscation of intent.

Sometimes I find I need to add specificity to just one of the types, it would be nice if this could be expressed as:
```
useProp<_, _, float>();
```
Instead of the current:
```
useProp();
```
I've had to do this when there is some ambiguity to the inferred types, and you need to add a little bit of an extra hint to the compiler.

An example of such a case is like this:
```
class Thing {}
void useThing(Thing t, T value) {}

void fn() {
//Thing t is declared to be of type bool
Thing t = Thing();
// But somehow, this is not an error...
useThing(Thing(), 1); // No error here :(
// We need to give it another hint;
useThing(Thing(), 1); //Now we have an error :)
}
```

If Thing was instead Thing this gets pretty annoying. The fact it falls to dynamic here is also annoying, but I guess that is a separate issue, or maybe a linter rule I'm missing.

Contributor guide

Open the contributing guide

Research direction

The issue names no implementation files, tests, or entry points. Start by reviewing the proposed partial type-argument syntax and the Thing inference example, then determine the language behavior that would need to be specified. Done means reaching a decision on optional generic arguments and the related 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.