dart-lang / dart-lang/language

Unused parameters interact poorly with inference_failure_on_untyped_parameter

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

Description

Sometimes you write a function that needs to take a parameter, but doesn't intend to use that parameter at all. Sometimes that function is passed in an untyped context—this is especially common when doing JS interop, because JS is untyped *and* often passes extra parameters as "extra data" (because JavaScript doesn't care if a function takes fewer parameters than are actually passed).

I've been dealing with this using the common cross-language idiom of declaring unused parameters as `_` (or `__`/`___`/etc if there are multiples). Upon upgrading to Dart 2.6, though, this started producing a bunch of annoying `inference_failure_on_untyped_parameter` warnings, because these parameters' types couldn't be inferred. I can write `void` before them, but it's annoying to have to do so much extra work for each of these parameters when I'm not even using them.

I propose that Dart treat parameters named `_` specially, by not introducing them as names to the current scope and having their type default to `void` rather than `dynamic`. This would enforce the convention that these parameters cannot be used, and it would allow a function to declare multiple unused parameters all named `_` rather than having to add additional underscores to each one. It would also avoid these annoying warnings.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.