Skip to content

consider pointing to required keyword when reporting errors for non-nullable named parameter without default value #44329

Closed
@mraleph

Description

@mraleph
class X {
  final String y;
  X({this.y});
}

produces in analyzer

Analyzing /tmp/test.dart...
  error • The parameter 'y' can't have a value of 'null' because of its type, and no non-null default value is provided. • /tmp/test.dart:3:11 • missing_default_value_for_parameter
1 error found.

This error message seems to indicate that the only way to address this error is to provide non-null default value. However this is not true - you can either provide a default value or use required keyword. I think this error message in both CFE and analyzer should be ammended to list both alternatives to be more user friendly.

This report is based on user report from Reddit

I think this also indicates that we might want to go through all error messages added in NNBD release and look at them from the perspective of UX and whether or not they are immediately actionable and clear even for the users who are encountering them for the first time. /cc @leafpetersen

/cc @stereotype441 @johnniwinther

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD ReleaseP1A high priority bug; for example, a single project is unusable or has many test failuresdevexp-uxlegacy-area-analyzerUse area-devexp instead.legacy-area-front-endLegacy: Use area-dart-model instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions