Skip to content

Analyzer does not consistently consider invocations on Never to have type Never. #56985

Open
@stereotype441

Description

@stereotype441

The NNBD spec says:

Calling a method (including an operator) or getter on a receiver of static type Never is treated by static analysis as producing a result of type Never. Tearing off a method from a receiver of static type Never produces a value of type Never. Applying an expression of type Never in the function position of a function call produces a result of type Never.

Assuming "operator" means "user-definable operator" (i.e. not &&, ||, or ??), then as far as I can tell, the CFE implements this faithfully.

The analyzer is inconsistent, though:

  • expr1 operator expr2, where expr1 has static type Never, has static type Never, as specified.
  • expr(args), where expr has static type Never, has static type Never, as specified.
  • expr.identifier(args), where expr has static type Never, has static type Never, as specified.
  • identifier1.identifier2, where identifier1 has static type Never, has static type Never, as specified.
  • expr.identifier, where expr is an expression having static type Never, but is not a simple identifier, behaves as follows:
    • If identifier is hashCode, toString, runtimeType, or noSuchMethod, the type is the same as it would be if the receiver type were Object (e.g. (throw '').toString has type String Function()).
    • Otherwise, the type is InvalidType, but no error is issued.
  • In an extension whose on type is Never, identifier and identifier(args) are treated the same as they would be treated if the on type were Object.

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.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