Skip to content

Allow member accesses to Never #40055

@eernstg

Description

@eernstg

Member accesses on Never should be allowed (cf. dart-lang/language#711 (comment)) and issues arising because the resulting code is likely to be a bug should be handled by detecting and flagging unreachable code with a warning.

So a receiver of type Never is treated as if it had all member signatures, just like a receiver of type dynamic, but n.foo() where n has type Never should be flagged with a warning indicating that the invocation of foo will not occur.

However, the log https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket.appspot.com/8891663887450837936/+/steps/test_results/0/logs/new_test_failures__logs_/0 shows that the analyzer reports an error for such a situation.

The situation occurs in static_errors_A11_t02:

main() {
  Null a = null;
  a?.toString();
  a ?.. toString();
}

where the receiver a is treated as having type NonNull(Null), which is Never. In the log, the analyzer reports that a receiver of type Never is an error per se:

ERROR|STATIC_WARNING|INVALID_USE_OF_NEVER_VALUE|/b/s/w/ir/cache/builder/sdk/tests/co19/src/LanguageFeatures/nnbd/static_errors_A11_t02.dart|25|3|1|This expression is invalid because its target is of type Never and will never complete with a value

It might be sufficient to change this response such that it is not an error but a warning (according to test.dart), and adjust the text to mention that there is dead code at this location.

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions