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

Getter + increment haxe.Int64 variable compile error #11605

Open
yuxiaomao opened this issue Mar 12, 2024 · 6 comments
Open

Getter + increment haxe.Int64 variable compile error #11605

yuxiaomao opened this issue Mar 12, 2024 · 6 comments
Milestone

Comments

@yuxiaomao
Copy link
Contributor

Recently, the following example does not compile, with message "haxe.Int64 should be Int". However, we should be able to increment an haxe.Int64 value. Without getter or without increment, the code compile correctly.

static var uid(get,default) : haxe.Int64;
static var __uid : haxe.Int64 = 0;
static inline function get_uid():haxe.Int64 return __uid;
static var uid2 : haxe.Int64 = 0;

static public function main() {
	uid++; // Error "haxe.Int64 should be Int"
	uid += 1; // Ok
	uid2++; // Ok
}

The first bad commit is a57c74c which is also related to the issue about setter and increment #11577

@kLabz
Copy link
Contributor

kLabz commented Mar 20, 2024

Same issue there:

	static inline function allocUID() : UID {
		return (SEQ << (#if hxbit64 64 #else 32 #end - SEQ_BITS)) | (++UID);
	}

With hxbit.UID should be Int on ++UID. Reverting a57c74c fixes that.

@Simn
Copy link
Member

Simn commented Mar 20, 2024

I have no intuition for how accessor + operator overload should interact here. Should this behave the same way as the += case or what?

@yuxiaomao
Copy link
Contributor Author

The case of @kLabz is exactly why I open this issue. I'm replacing it locally to continue my dev, with

UID += 1;
return (SEQ << (#if hxbit64 64 #else 32 #end - SEQ_BITS)) | (UID);

@ncannasse
Copy link
Member

@Simn if we have a + operator, we should be able to use += and prefix/postfix ++ , by generating the following code:

x += 1; // x = X.add(x,1)
++x; // same
x++;  // { var tmp = x; x = X.add(x,1); tmp; }

@Simn
Copy link
Member

Simn commented Mar 29, 2024

Ok hang on, the specification is really not clear to me. We can have three different kinds of operator overload:

  1. @:op(A + B)
  2. @:op(A += B)
  3. @:op(++A)

If I'm understanding what you're saying correctly, the following should be true:

  1. An expression a + b only checks for @:op(A + B)
  2. An expression a += b checks for @:op(A += B), and if that's not applicable it checks for @:op(A + B)
  3. An expression ++a checks for @:op(++A), and if that's not applicable it checks for @:op(A += B), and if that's not applicable it checks for @:op(A + B)

Is that correct? Note that I'm not even talking about getters/setters because it seems like the problem here starts even earlier.

@yuxiaomao
Copy link
Contributor Author

I thought that @:op(A++) is defined for haxe.Int64 which will performs an add1 (seems quite natural for me as that's an Int), I must have misunderstood something :'(
If I recall correctly, @ncannasse said that ++ on String should not be valid (but there is a + on String), so I do not think ++ should automatically performs a +1

@kLabz kLabz added this to the 5.0 preview 1 milestone Apr 29, 2024
@kLabz kLabz modified the milestones: 5.0 preview 1, Release 5.0 Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants