Project

General

Profile

Bug #11089

equals functions are not translated properly

Added by Roel Standaert 12 days ago. Updated 12 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Target version:
Start date:
11/21/2022
Due date:
% Done:

0%

Estimated time:

Description

We turn the following C++:

class C {
public:
  bool operator==(const C& other) {
    ...
  }
};

into:

public class C {
  public boolean equals(final C other) {
    ...
  }
}

As a consequence, Object#equals is not properly overridden.

We should turn it into something like:

public class C {
   @Override
   public boolean equals(Object otherObject) {
     if (!(otherObject instanceof C)) {
       return false;
     }
     final C other = (C)otherObject;
     ...
   }
}

One function that is affected by this issue is WApplication#require. If require is called twice:

require("lib.js"); // returns true
require("lib.js"); // ERROR: also returns true

This also generates JavaScript like:

Wt._p_.loadScript('lib.js', '');
Wt._p_.onJsLoad('lib.js', function() {
  Wt._p_.loadScript('lib.js', '');
  Wt._p_.onJsLoad('lib.js', function() {
    ...

Instead, it should be:

Wt._p_.loadScript('lib.js', '');
Wt._p_.onJsLoad('lib.js', function() {
  ...

Related to this is the fact that hashCode is rarely properly overridden.

No data to display

Also available in: Atom PDF