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

Could not compare null with nullable type #2662

Open
yjhmelody opened this issue Mar 3, 2023 · 4 comments · May be fixed by #2760
Open

Could not compare null with nullable type #2662

yjhmelody opened this issue Mar 3, 2023 · 4 comments · May be fixed by #2760
Labels

Comments

@yjhmelody
Copy link
Contributor

yjhmelody commented Mar 3, 2023

Bug description

TS2322: Type '~lib/as-bignum/assembly/integer/u128/u128 | null' is not assignable to type '~lib/as-bignum/assembly/integer/u128/u128'.
     :
 278 │ return value === null || !(value.lo | value.hi);
     │                  ~~~~
     └─ in ~lib/as-bignum/assembly/integer/u128.ts(278,22)

Steps to reproduce

let x: string | null = "foo";
assert(null != x);

WARNING AS226: Expression resolves to unusual type 'usize'.
   :
 3  assert(null != x);
           ~~~~
   └─ in foo.ts(3,8)

ERROR TS2365: Operator '!=' cannot be applied to types 'usize' and '~lib/string/String | null'.
   :
 3  assert(null != x);
           ~~~~~~~~~
   └─ in foo.ts(3,8)

FAILURE 1 compile error(s)

let data: u128 | null = u128.Max;
assert(data != null);

ERROR TS2322: Type '~lib/as-bignum/assembly/integer/u128/u128 | null' is not assignable to type '~lib/as-bignum/assembly/integer/u128/u128'.
     :
 327  assert(data != null);

The as-bignum u128 has the following operator overload:

  @inline @operator('==')
  static eq(a: u128, b: u128): bool {
    return a.hi == b.hi && a.lo == b.lo;
  }

  @inline @operator('!=')
  static ne(a: u128, b: u128): bool {
    return !u128.eq(a, b);
  }

AssemblyScript version

v0.25 ~ v0.27

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Mar 7, 2023

@HerrCai0907 Hi, there is another kind type error. See the above examples.

TBH, it's huge break change.

@yjhmelody
Copy link
Contributor Author

yjhmelody commented Mar 7, 2023

@MaxGraey Maybe the as-bignum should handle this problem rather than AssemblyScript?

I really don't understand the specific semantics and scope of overloading != and ==,

@yjhmelody
Copy link
Contributor Author

I always feel that we always need non-overloadable reference comparison and overloadable comparison

@HerrCai0907
Copy link
Member

The second issue seems like another problem related with operator overload.

@HerrCai0907 HerrCai0907 linked a pull request Oct 7, 2023 that will close this issue
HerrCai0907 added a commit to HerrCai0907/assemblyscript that referenced this issue Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants