AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.79k stars 655 forks source link

There is problem with some classes whose parent class have @operator decorated #1779

Closed yjhmelody closed 3 years ago

yjhmelody commented 3 years ago

See my repo https://github.com/yjhmelody/as-container/blob/overload-for-subclass/assembly/__tests__/box.spec.ts#L112

The test is always passed.

How to test

yarn

yarn test
MaxGraey commented 3 years ago

Could you try:

 expect(b3 == b4).toStrictEqual(true);
 expect(b3 != b4).toStrictEqual(false);

Does it change something?

yjhmelody commented 3 years ago

Could you try:

 expect(b3 == b4).toStrictEqual(true);
 expect(b3 != b4).toStrictEqual(false);

Does it change something?

Yes, I meet compiling errors.

ERROR TS2322: Type 'bool' is not assignable to type 'assembly/box/Box<bool>'.

         expect(b3 == b4).toStrictEqual(true);
                                        ~~~~
 in assembly/__tests__/box.spec.ts(120,40)

ERROR TS2322: Type 'bool' is not assignable to type 'assembly/box/Box<bool>'.

         expect(b3 != b4).toStrictEqual(false);
                                        ~~~~~
 in assembly/__tests__/box.spec.ts(121,40)

The True/False are Box version of true/false.

yjhmelody commented 3 years ago

I try to write a minimal example to reproduce it but I failed. I don't know why.

BTW, the static method from in Box2 return Box rather than Box2.

MaxGraey commented 3 years ago

Hmm, but why you return eq:: Box -> Box -> Box intead eq:: Box -> Box-> bool ?

yjhmelody commented 3 years ago

Hmm, but why you return eq:: Box -> Box -> Box intead eq:: Box -> Box-> bool ?

Because primitve cannot be null, So I always return box version. But this kind of design shouldn't cause this kind of logical problem.

MaxGraey commented 3 years ago

Rust for example always return bool for Ord/PartialOrd

yjhmelody commented 3 years ago

Rust for example always return bool for Ord/PartialOrd

Well, when I change the APIs to rust style, the problem disappeared. But still need to know why there is such a problem.

yjhmelody commented 3 years ago

Rust for example always return bool for Ord/PartialOrd

I think the API means to deref box internally, so it return bool. But in as if we want to operate in generic class, I think always keep it Box version is fine and more consistent.

And my box is for primitve type which cannot be null, is not a rust semantic box.

MaxGraey commented 3 years ago

Basically Box container makes sense only for Rust-like languages which alloc all variables on stack by default. TS/Kotlin/Swift/Haskell hasn't this container in stdlib

yjhmelody commented 3 years ago

Basically Box container makes sense only for Rust-like languages which alloc all variables on stack by default. In TS/Kotlin/Swift/Haskell hasn't this container in stdlib

yeah, I see. It's used to wrap primitive type just like Java boxing type.

Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.

as Cannot autoboxing, so I defined this type.

yjhmelody commented 3 years ago

Rust for example always return bool for Ord/PartialOrd

I have thought about it these days, and it is indeed better to return a Boolean value than its Box version. Anyway, thank you for your suggestion

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!