Skip to content

Spec does not forbid using a non-const superconstructor from a const constructor #11626

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
rakudrama opened this issue Jun 29, 2013 · 4 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Milestone

Comments

@rakudrama
Copy link
Member

I can't find anything prohibiting the problem in issue #11624.

Section "7.6.3 Constant Constructors" does not appear to restrict the superconstructor used by a const constructor's initializers.
I did not find a restriction elsewhere.

@gbracha
Copy link
Contributor

gbracha commented Jun 29, 2013

Added Accepted label.

@DartBot
Copy link

DartBot commented Jul 1, 2013

This comment was originally written by @mhausner


I spoke with Gilad about this. The simple rule 'a const constructor can only call const super constructors" does not work because class Object does not have a const constructor. This is a problem because a missing super call in the initializer list implies a call to the nullary constructor of the super class.

class Point {
  final x, y;
  const Point(this.x, this.y); <<< implicit call to non-const constructor Object().
}

We have several options:

  1. We can add an exception that a super call to the nullary non-const constructor of class Object is allowed.
  2. We can define the (nullary) constructor of class Object to be const.

In the case of 2), the consequence is that 'const Object()" is legal and must return a canonicalized instance of type Object.


cc @kasperl.
cc @larsbak.
cc @iposva-google.
cc @mhausner.

@DartBot
Copy link

DartBot commented Jul 1, 2013

This comment was originally written by @mhausner


As it turns out, our core library already defines the constructor of class Object to be const. The spec does not describe the interface of Object, so it may not have to mention this fact.

/**
 * Everything in Dart is an [Object].
 /
class Object {
  /**
   
Creates a new [Object] instance.
   *
   * [Object] instances have no meaningful state, and are only useful
   * through their identity. An [Object] instance is equal to itself
   * only.
   */
  const Object();
  ...

@gbracha
Copy link
Contributor

gbracha commented Jul 1, 2013

I have added the requirement that the superinitializer used in a constant constructor (implicitly or explicitly) must denote a const constructor of the superclass.


Added Done label.

@rakudrama rakudrama added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jul 1, 2013
@rakudrama rakudrama added this to the M6 milestone Jul 1, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants