Skip to content

Warning for parameter hiding on ignored parameters #3099

Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


Here's the setup: I have nested asynchronous methods that each take a callback, and I don't care about the event being passed to the callback. For (potentially contrived) example:

var button = document.query('#some-button');
button.on.click.add((_) { // <-- I don't care about the Event, I'll call it \_
  // Button is clicked
  // ...set up some more UI...
  var anotherButton = document.query('#another-button');
  anotherButton.on.click.add((_) => window.alert('Success!')); // <-- I don't care about this Event either
});

This may be a contrived example, and in retrospect I'm not sure where I got the idea to name things _ when I don't care about them, this might be a personal convention or I may have cargo culted it from Go. If it isn't a style recommendation something like it should be perhaps.

My point is, I currently see a warning when the inner _ hides the outer _. But I don't really care, I don't care about either of them. I can rename the second to __ or something, but this arms race quickly becomes annoying.

It might be nice if Dart considered variables named _ as totally ignored placeholders, not caring if they hide other parameters, and potentially showing warnings/errors if they're ever actually used (e.g., _.size or _.stopPropagation()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-not-plannedClosed as we don't intend to take action on the reported issuetype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions