Sprite not get cleared and no compiler error for "this.graphics.clear;"

58 views
Skip to first unread message

Mark

unread,
Dec 2, 2014, 9:39:50 AM12/2/14
to haxe...@googlegroups.com
hey guys,

I just made a huge mistake in my code. I wrote this:

this.graphics.clear;

Just before I started drawing Tiles. I was struggling for a shamingly long time with this, as the Sprite did not get cleared and took a while to realize I simply forgot to add (), so the code of course (as everywhere else in my code) should look like this:

this.graphics.clear();

As this is a function call, not a property.


My concern is, I did not get neither compile-time nor run time error. Run time is OK, might be sinked or not, fine. But compile time?
I think this is a bug as -IMHO- compiler should throw an error ("graphics obj. has no 'clear' property. did you mean clear()?" or similar) and considering this should be the case many other places if not everywhere else, I think the issue is severe.

Please let me know if I'm wrong.


Cheers,
Mark

David Peek

unread,
Dec 2, 2014, 11:55:37 AM12/2/14
to haxe...@googlegroups.com
var ref = this.graphics.clear;
ref();

David Peek

unread,
Dec 2, 2014, 12:06:18 PM12/2/14
to haxe...@googlegroups.com
By which I mean functions are values. So the compiler doesn't complain for the same reason it's ok with:

{};
10;
[];

Which seems pointless until you understand that Haxe uses the last expression of a block as its value: http://try.haxe.org/#ca57E

On Tuesday, 2 December 2014 14:39:50 UTC, Mark wrote:

Hugh

unread,
Dec 2, 2014, 11:52:30 PM12/2/14
to haxe...@googlegroups.com
But the compiler can tell the difference between:
var ref = this.graphics.clear;
and
this.graphics.clear;
One of the being almost certainly wrong, and I too think there should be a warning (or error, given haxe does not really do warnings).

I don't think we want to become java, which throws an error for unreachable code etc, but I think this one is a good one.

Hugh

PSvils

unread,
Dec 3, 2014, 1:48:27 AM12/3/14
to haxe...@googlegroups.com
This should be a warning of an unused reference or something at most, but not an error imo.

Mark

unread,
Dec 3, 2014, 7:41:43 AM12/3/14
to haxe...@googlegroups.com
Just to support our point :)

http://try.haxe.org/#7d141

i.e.
1. Doing it the other way, trying to have "myRandomMemberName" property as well as "myRandomMemberName()" function throws an error)

2. Trying to call a property with "()" also throws an error

Vice-versa sinking is clearly a double standard which should not be OK for a programming language (IMHO)

PSvils

unread,
Dec 3, 2014, 8:01:55 AM12/3/14
to haxe...@googlegroups.com
I'm not sure I understand your reasoning...you can reference a function, therefore your initial issue was with a totally valid statement. Hugh showed a case where the compiler could dispatch a warning.


"1. Doing it the other way, trying to have "myRandomMemberName" property as well as "myRandomMemberName()" function throws an error)"
That's not doing it the other way around, that's defining 2 class fields with the same name.


"2. Trying to call a property with "()" also throws an error"
That doesn't make sense in the least. :)

A function is a field of a class, it makes no sense to not allow access to it. I suppose the compiler COULD detect this case as well, but I think it makes more sense to just be more careful :)
http://try.haxe.org/#139Ec

Mark

unread,
Dec 3, 2014, 9:55:29 AM12/3/14
to haxe...@googlegroups.com

RE 1: No, one is property, the other if function. Just as it's in the sample. Yours compile, true, but did you run it? The result value is not very satisfying :)

RE 2: It does but I zapped what I meant indeed. So what I was trying to point out is, "referencing a property the wrong way", i.e. accidentally adding "()" (function brackets), however, the member one is about to touch is a property, not a method.


Anyways. It's not my call to decide about warnings/errors/etc. I just pointed out what I did, do devs whatever they want with it.

David Peek

unread,
Dec 3, 2014, 4:01:02 PM12/3/14
to haxe...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages