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

void is not supported as a generic method type argument #26275

Closed
jmesserly opened this issue Apr 15, 2016 · 7 comments
Closed

void is not supported as a generic method type argument #26275

jmesserly opened this issue Apr 15, 2016 · 7 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug

Comments

@jmesserly
Copy link

Reported by @jacob314 over at dart-archive/dev_compiler#496


Repro:

wrapZone/*<E, R>*/(/*=R*/ callback(/*=E*/ evt)) {

}
...
wrapZone/*<Event, void>*/(someCallback).
@jmesserly jmesserly added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-strong-mode P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Apr 15, 2016
@jmesserly
Copy link
Author

jmesserly commented Apr 15, 2016

CC @leafpetersen

It'd be nice to have some consistency around void -- this was something I always found annoying about generic function types in C# (and our func.dart package has a similar problem)

That said this seems like a Dart 2 issue, rather than something we can address in the short term.

(Future<void> is a similar one, we get that style question a lot from folks)

@zoechi
Copy link
Contributor

zoechi commented Apr 16, 2016

Shouln't it be Null instead of void or is this about support void as alternative to Null?

@lrhn
Copy link
Member

lrhn commented Apr 16, 2016

In Dart, void is not a type expression. It's something you can write instead of a type expression as the return type of a function. So, you can't use it as a type parameter, even if the type parameter is going to be used as a return type.

In this particular case, I'd consider parameterizing the class with the function type instead of with the parameter and return type:

wrapZone/*<F extends UnaryFunction>*/(/*=F*/ callback)

Persoanlly, I'd accept void as a type anywhere. It doesn't make a lot of sense as a parameter type, but if you really want it, I don't have a problem with that.

(The "void" type represents the empty type, a type with no value, hence the name. It doesn't make sense in places other than return types because you can never produce a value of that type - and for return types it only makes sense because null is assignable to any type, even void - with non-nullable types, a void! function would be one that never returns, e.g., always throws).

@jmesserly
Copy link
Author

CC @leafpetersen ... does it make sense to kick this to area-language instead of strong-mode. I don't think there's anything actionable we can do in the implementation

@jmesserly
Copy link
Author

I'm going to reclassify this as area-language, I don't think it's something we can address via strong mode

@jmesserly jmesserly added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed analyzer-strong-mode area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on labels Aug 9, 2016
@leafpetersen
Copy link
Member

Under consideration for the language.

@munificent
Copy link
Member

De-duping with newer but more active other issue: #27504.

@munificent munificent added the closed-duplicate Closed in favor of an existing report label Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-duplicate Closed in favor of an existing report type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants