Skip to content

Optional parameters with potentially non-nullable types can omit default values in abstract methods #516

@scheglov

Description

@scheglov

There are new test failures on Issue 40287. Don't report MISSING_DEFAULT_VALUE_FOR_PARAMETER for abstract methods..

The tests

co19/LanguageFeatures/nnbd/override_checking_A02_REQ_ARGS_t10 MissingCompileTimeError (expected Pass)
co19/LanguageFeatures/nnbd/override_checking_A02_REQ_ARGS_t12 MissingCompileTimeError (expected Pass)
co19/LanguageFeatures/nnbd/override_checking_A02_REQ_ARGS_t14 MissingCompileTimeError (expected Pass)

are failing on configurations

analyzer-asserts-strong-linux

The spec says:

It is an error if an optional parameter (named or otherwise) with no default value has a potentially non-nullable type except in the parameter list of an abstract method declaration.

@eernstg @leafpetersen One possible question here however is whether we need to validate the implicit default value (i.e. null) against the parameter type, because if we need, then Null is not assignable to int, and there is still an error.
image

@eernstg @leafpetersen Also, the spec does not seem to make any exclusion for abstract methods and the requirement that default values for parameters must be identical. So, we need to report a warning here?
image

I'm going to land my CL, because the NNBD spec is unequivocal about abstract methods, and the language spec is less clear.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions