Skip to content

[Bug]: Adding int:unsigned32 to int:unsigned32 via += doesn't work #44416

@KieranP

Description

@KieranP

Description

This doesn't work:

public class World {
  public int:Unsigned32 tick = 0;

  public function dotick() {
    self.tick += 1;
  }
}

The 1 is treated as int, so unsigned32+int coverts result to int, which isn't compatible with variables type. Makes sense. So I tried this:

public class World {
  public int:Unsigned32 tick = 0;

  public function dotick() {
    self.tick += <int:unsigned32> 1;
  }
}

But that didn't work, it still resulted in an int... I also tried this, same result:

public class World {
  public int:Unsigned32 tick = 0;

  public function dotick() {
    self.tick = self.tick + <int:unsigned32> 1;
  }
}

Finally, I got it working with this:

public class World {
  public int:Unsigned32 tick = 0;

  public function dotick() {
    self.tick = <int:unsigned32>(self.tick + 1);
  }
}

In the second example, why is self.tick += <int:unsigned32> 1; resulting in an int? At that point, shouldn't it be doing unsigned32+unsigned32 = unsigned32? I'd understand doing u32-u32, as that could be a negative number, but since you know that self.tick is a u32, and I'm adding a positive number, should the compiler be able to infer the resulting type can remain u32?

Steps to Reproduce

No response

Affected Version(s)

2201.13.1

OS, DB, other environment details and versions

Mac OS Tahoe

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions