Skip to content

Instantly share code, notes, and snippets.

@ryzed
Created November 30, 2013 15:04
Show Gist options
  • Save ryzed/7720147 to your computer and use it in GitHub Desktop.
Save ryzed/7720147 to your computer and use it in GitHub Desktop.
class AA
{
public var x:Float;
public var y:Float;
inline public function new(x:Float, y:Float)
{
this.x = x;
this.y = y;
}
}
abstract BB(AA)
{
public var x(get, set):Float;
public var y(get, set):Float;
inline public function get_x():Float return this.x;
inline public function get_y():Float return this.y;
inline public function set_x(v:Float):Float return this.x = v;
inline public function set_y(v:Float):Float return this.y = v;
public inline function new(x:Float = 0, y:Float = 0)
{
this = new AA(x, y);
}
@:commutative @:op(A*B) inline public static function opMulSF(a:BB, s:Float):BB
{
return new BB(a.x * s, a.y * s);
}
}
class Main
{
static function main()
{
var a = new BB(10, 20);
var t1 = 1.0;
var t2 = 2.0;
// !!! fails here
var fail = a * (t1 + t2);
// ok here
var cacheSum = (t1 + t2);
var ok = a * cacheSum;
}
}
var Main = function() { };
Main.main = function() {
var a_x = 10;
var a_y = 20;
var t1 = 1.0;
var t2 = 2.0;
var fail;
var s = t1 + t2;
fail = new AA(a_x * s,a_y * s);
var cacheSum = t1 + t2;
var ok_x = a_x * cacheSum;
var ok_y = a_y * cacheSum;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment