assemblyscript
assemblyscript copied to clipboard
Could not compare null with nullable type
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
@HerrCai0907 Hi, there is another kind type error. See the above examples.
TBH, it's huge break change.
@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 ==,
I always feel that we always need non-overloadable reference comparison and overloadable comparison
The second issue seems like another problem related with operator overload.