Open stereotype441 opened 3 weeks ago
I'm working on some refactoring that would benefit from fixing this, so I'll work on a fix. Note that the fix will be a non-breaking change, since it will bring the analyzer into alignment with the CFE.
Assuming "operator" means "user-definable operator"
It does here since it refers to "method (including an operator)" so it's about operators which are also instance methods.
Probably except ==
which always has type bool
.
(Although it could safely apply to the rest too, if the first operand has type Never
, the entire expression could soundly have type Never
.)
Every place where a non-Never
, non-dynamic
invocation would use the member signature of the member on the receiver type to infer the result type, an invocation on Never
has result type Never
, no bounds for type arguments and no context type or required type for arguments.
"Tearing off a method from a receiver of static type
Never
produces a value of typeNever
. "
That's a little misleading. It's an unspecified member access. It's impossible to say whether a member access on Never
targets a getter or a method. In fact, it's definitely neither.
Anyway, seems like the analyzer refused a little more of the behavior of dynamic
.
The only real problem with that is inconsistency, it'll never cause a runtime problem (he says confidently).
The NNBD spec says:
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
, whereexpr1
has static typeNever
, has static typeNever
, as specified.expr(args)
, whereexpr
has static typeNever
, has static typeNever
, as specified.expr.identifier(args)
, whereexpr
has static typeNever
, has static typeNever
, as specified.identifier1.identifier2
, whereidentifier1
has static typeNever
, has static typeNever
, as specified.expr.identifier
, whereexpr
is an expression having static typeNever
, but is not a simple identifier, behaves as follows:identifier
ishashCode
,toString
,runtimeType
, ornoSuchMethod
, the type is the same as it would be if the receiver type wereObject
(e.g.(throw '').toString
has typeString Function()
).InvalidType
, but no error is issued.on
type isNever
,identifier
andidentifier(args)
are treated the same as they would be treated if theon
type wereObject
.