Skip to content

Static getter or setter declaration doesn't add an instance one to the Type object #23721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sgrekhov opened this issue Jun 26, 2015 · 5 comments
Labels
area-specification (deprecated) Deprecated: use area-language and a language- label.

Comments

@sgrekhov
Copy link
Contributor

According Dart specification (2-n Edition, December 2014) p. 10.2

"The effect of a static getter declaration in class C is to add an instance getter with the same name and signature to the Type object for class C that forwards (9.1) to the static getter."

But in fact no getter/setter instance added to the Type object. The following code demonstrates the issue:

class C {
  static get g => 1;
}

main() {
  C c = new C();
  Type t = c.runtimeType;
  var x = t.g;  //throws NoSuchMethodError
}
@floitschG floitschG added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed Area-NONE labels Jun 29, 2015
@munificent munificent added area-specification (deprecated) Deprecated: use area-language and a language- label. and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Dec 14, 2016
@munificent
Copy link
Member

Yes, the spec does indeed seem to imply that static members on classes become instance members on result of calling runtimeType on an instance of that class.

That's something we've talked about forever, but as far as I know, we did not decide to do that. The implementations certainly don't, so I don't see why the spec says they should. As far as I know, this should be removed from the spec.

@lrhn
Copy link
Member

lrhn commented Dec 14, 2016

The spec also goes out of its way to make those getters and setters invisible again.
From section 16.18.1 (Getter Access and Method Extraction):

Otherwise, i is a getter invocation. Let f be the result of looking up (16.15.2) getter (10.2) m in o with respect to L. If o is an instance of Type but e is not a constant type literal, then if f is a getter that forwards to a static getter, getter lookup fails.

That's a roundabout way of saying that the getter on the Type object introduced by a static declaration cannot be looked up on the Type object in general. It only works if you do a static access directly on the type as a literal. So C.g works, but t.g doesn't.

In effect, it's indistinguishable from having Type objects without the static members and special semantics rules for member access on a type literal.

Technically it's working as intended, but we might want to streamline the spec a little at some point in the future.

@eernstg
Copy link
Member

eernstg commented Feb 6, 2018

No milestone now: This clarification should be considered and possibly performed, but this will not block Dart 2.

@eernstg
Copy link
Member

eernstg commented Aug 24, 2018

All these sentences that amount to a specification of a kind of "meta classes" (where each Type instance t would have instance members corresponding to the static members of the class represented by t) will be deleted, because that feature is no longer planned. We will then, of course, also need to remove the twisted wording which annihilates those instance methods again (that's all those if .. forwards to a static .. lookup fails).

@eernstg
Copy link
Member

eernstg commented Jan 18, 2019

Closing: All text concerned with "meta classes" has been removed from the language specification as of 614ae7f, in particular the text which gave rise to this issue.

@eernstg eernstg closed this as completed Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-specification (deprecated) Deprecated: use area-language and a language- label.
Projects
None yet
Development

No branches or pull requests

6 participants