Skip to content

What is the intended behavior of C.toString() where C is a class? #26024

Closed
@kmillikin

Description

@kmillikin

Both the VM and dart2js throw a NoSuchMethodError, but I can't quite see where the spec mandates that.

From 16.14.4 Function Expression Invocation we have:

A function expression invocation i has the form
ef (a1, . . . , an, xn+1 : an+1, . . . , xn+k : an+k),
where ef is an expression. If ef is an identifier id, then id must necessarily denote a local function, a library function, a library or static getter or a variable as described above, or i is not considered a function expression invocation. If ef is a property extraction expression (16.18), then i is is not a function expression invocation and is instead recognized as an ordinary method invocation (16.17.1).

So this is not a function expression invocation and is instead an ordinary method invocation.

From 16.17.1 Ordinary Invocation we have:

Evaluation of an unconditional ordinary method invocation i of the form
o.m(a1, . . . , an, xn+1 : an+1, . . . , xn+k : an+k)
proceeds as follows:
First, the expression o is evaluated to a value vo. Next, the argument list (a1, . . . , an, xn+1 : an+1, . . . , xn+k : an+k) is evaluated yielding actual argument objects o1, . . . , on+k. Let f be the result of looking up (16.15.1) method m in vo with respect to the current library L.

The expression C is evaluated to a value vo. From 16.33 Identifier Reference we have:

If d is a class or type alias T, the value of e is an instance of class Type (or a subclass thereof) reifying T.

So vo is an instance of class Type or a subclass thereof reifying C. From 16.15.1 Method Lookup we have:

The result of a lookup of a method m in object o with respect to library L is the result of a lookup of method m in class C with respect to library L, where C is the class of o.
The result of a lookup of method m in class C with respect to library L is: If C declares a concrete instance method named m that is accessible to L, then that method is the result of the lookup, and we say that the method was looked up in C. Otherwise, if C has a superclass S, then the result of the lookup is the result of looking up m in S with respect to L. Otherwise, we say that the method lookup has failed.

And https://api.dartlang.org/stable/1.15.0/dart-core/Type-class.html seems to indicate that the lookup will find the method toString from a superclass.

All the stuff about parameter matching seems to succeed and we get back to 16.17.1 Ordinary Invocation:

If vo is an instance of Type but o is not a constant type literal, then if m is a method that forwards (9.1) to a static method, method lookup fails. Otherwise method lookup has succeeded.
If the method lookup succeeded, the body of f is executed with respect to the bindings that resulted from the evaluation of the argument list, and with this bound to vo. The value of i is the value returned after f is executed.

In this case vo is an instance of Type but o is a constant type literal, so we're OK and we should invoke the method toString from a superclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions