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

toStrictEqual meets error when used in such situation #339

Open
yjhmelody opened this issue Apr 26, 2021 · 1 comment
Open

toStrictEqual meets error when used in such situation #339

yjhmelody opened this issue Apr 26, 2021 · 1 comment

Comments

@yjhmelody
Copy link

yjhmelody commented Apr 26, 2021

I define a Option:

export class Option<T> {
    @inline
    constructor(
        protected readonly _val: Box<T> | null = null,
        protected _isNone: bool = true
    ) {}


    @inline
    static Some<T>(val: T): Option<T> {
        return new Option<T>(Box.from(val), false);
    }

    @inline
    static None<T>(): Option<T> {
        return new Option<T>(null, true);
    }

    @inline
    @operator("==")
    eq(other: Option<T>): bool {
        return this._val == other._val;
    }

    @inline
    @operator("!=")
    notEq(other: Option<T>): bool {
        return !this.eq(other);
    }

   // ...

And the Box:

export class Box<T> {
    constructor(protected readonly val: T) {}

    /**
     * Create a Box version of value
     * @param val boxed value
     * @returns value of Box version
     */
    @inline
    static from<T>(val: T): Box<T> {
        return new Box(val);
    }

    @inline
    @operator("==")
    eq(other: this | null): bool {
        if (other === null) return false;
        return this.val == other.val;
    }

    @inline
    @operator("!=")
    notEq(other: this | null): bool {
        if (other === null) return false;
        return this.val != other.val;
    }
   // ...
}

But I cannot do toStrictEqual for option.

unexpected null
   [Stack]: RuntimeError: unreachable
            at node_modules/@as-pect/assembly/assembly/internal/Reflect/Reflect.equals<assembly/box/Box<assembly/__tests__/primitive/option.spec/Person>|null> (<anonymous>:wasm-function[98]:0x26b8)
            at assembly/primitive/option/Option<assembly/__tests__/primitive/option.spec/Person>#__aspectStrictEquals (<anonymous>:wasm-function[100]:0x272c)
            at node_modules/@as-pect/assembly/assembly/internal/Reflect/referencesEqual<assembly/primitive/option/Option<assembly/__tests__/primitive/option.spec/Person>> (<anonymous>:wasm-function[101]:0x28bd)
            at node_modules/@as-pect/assembly/assembly/internal/Reflect/Reflect.equals<assembly/primitive/option/Option<assembly/__tests__/primitive/option.spec/Person>> (<anonymous>:wasm-function[102]:0x2953)
            at node_modules/@as-pect/assembly/assembly/internal/Reflect/Reflect.equals<assembly/primitive/option/Option<assembly/__tests__/primitive/option.spec/Person>>@varargs (<anonymous>:wasm-function[104]:0x29fb)
            at node_modules/@as-pect/assembly/assembly/internal/Expectation/Expectation<assembly/primitive/option/Option<assembly/__tests__/primitive/option.spec/Person>>#toBe (<anonymous>:wasm-function[108]:0x2ae2)
            at start:assembly/__tests__/primitive/option.spec~anonymous|0~anonymous|1 (<anonymous>:wasm-function[109]:0x2b7d)
            at node_modules/@as-pect/assembly/assembly/internal/call/__call (<anonymous>:wasm-function[208]:0x5241)
@jtenner
Copy link
Contributor

jtenner commented Apr 28, 2021

I will definitely take a look into this soon. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants