Skip to content
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

Many constructors can be generated dynamically #8827

Closed
peter-ahe-google opened this issue Feb 27, 2013 · 8 comments
Closed

Many constructors can be generated dynamically #8827

peter-ahe-google opened this issue Feb 27, 2013 · 8 comments

Comments

@peter-ahe-google
Copy link
Contributor

Given this class:

class Point {
  var x;
  var y;
  Point(this.x, this.y);

  operator +(Point other) {
    return new Point(x + other.x, y + other.y);
  }

  String toString() => "($x, $y)";
}

dart2js will generate:

$$.Point = {"": "Object;x>,y>",
  toString$0: function() {
    return "(" + $.S(this.x) + ", " + $.S(this.y) + ")";
  }
};
$.Point$ = function(x, y) {
  return new $.Point(x, y);
};

The latter is the constructor, and it can be generated dynamically, or even:

$.Point$ = $.Point;

@rakudrama
Copy link
Member

I don't think the the assignment version works - it is missing the 'new'.

The compiler should probably inline trivial constructors like this unless there are so many calls (> 10) that the short-hand of the constructor function is a valuable contraction.

@peter-ahe-google
Copy link
Contributor Author

Yes, the assignment version won't work.

Also, $.Point$ is not the constructor, it is the factory.

@kasperl
Copy link

kasperl commented Apr 22, 2013

Added this to the Later milestone.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@karlklose
Copy link
Contributor

Verified fixed in 79a8654.

@kevmoo kevmoo removed the triaged label Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants