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

Give a different warning if @required is used on a positional parameter #36966

Open
gspencergoog opened this issue May 14, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@gspencergoog
Copy link

commented May 14, 2019

In this class:

class Action {
  const Action(@required this.name);
  final String name;
}

The analyzer gives the warning: info: The type parameter 'name' is annotated with @required but only named parameters without default value can be annotated with it.

This is because name is a positional parameter and not a named parameter, but the error message makes it sound like a named parameter. The analyzer should print a different message along the lines of Redundant use of the annotation @required on a positional parameter. Positional parameters are always required.

Version: Dart VM version: 2.3.1-dev.0.0.flutter-a0290f823c (Thu May 9 07:43:56 2019 +0000) on "linux_x64"

@gspencergoog gspencergoog changed the title Give a different warning if @required is used on a positional argument Give a different warning if @required is used on a positional parameter May 14, 2019

@jacob314

This comment has been minimized.

Copy link
Member

commented May 14, 2019

Fyi @pq.

@pq

This comment has been minimized.

Copy link
Member

commented May 14, 2019

cc @bwilkerson (fyi)

@parlough

This comment has been minimized.

Copy link

commented May 16, 2019

I'm not sure this is the best message for all cases as not all positional parameters are required if my understanding is correct, with the ones defined within [] actually not required? For non optional positional parameters I think something like your suggested message would work, but for optional positional parameters, should a different warning and suggestion be made to make the parameter non optional as well as remove the @required annotation?

@gspencergoog

This comment has been minimized.

Copy link
Author

commented May 16, 2019

Yes, I get your point though. Perhaps three different cases then:

  1. On required positional parameter:
    Redundant use of the annotation @required on a required positional parameter.
  2. On optional positional parameter:
    Incorrect use of the annotation @required on an optional positional parameter. Optional positional parameters cannot be required.
  3. On a named parameter with a default:
    The type parameter 'name' is annotated with @required but only named parameters without default value can be annotated with it.
@parlough

This comment has been minimized.

Copy link

commented May 17, 2019

I gave this a shot as a first try at contributing if it is desired at https://dart-review.googlesource.com/c/sdk/+/102900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.