Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Failing test #1

Closed
alfonsogarciacaro opened this issue Nov 26, 2017 · 6 comments
Closed

Failing test #1

alfonsogarciacaro opened this issue Nov 26, 2017 · 6 comments

Comments

@alfonsogarciacaro
Copy link
Contributor

alfonsogarciacaro commented Nov 26, 2017

Copy & pasted from Slack so I don't forget ;)

This test is failing. It's probably related to how Fable translate the custom function.

You can debug doing: ./build.sh DotnetBuild, in a terminal : yarn run test and in another yarn run mocha ./tests/bin/ or press F5 into VSCode to be able to set breakpoint.

@MangelMaxime
Copy link
Owner

The latest message of @inosik in this issue fable-compiler/Fable#1199 (comment) about:

"thenAdd2 is not a function"

make me think of the error we are facing this project. Perhaps, I am using the point-free style without knowing it.

@alfonsogarciacaro
Copy link
Contributor Author

I just tried with Fable development version and the test passed 😸 I will release Fable 1.3.3 so you can give it a try.

I also got a warning message about this line so I recommend changing it to let decode x y = succeed x y 👌

@MangelMaxime
Copy link
Owner

@alfonsogarciacaro Awesome, so this was somehow related to the linked issue probably.

Yes, I was in the process to add explicit arguments in every function. Thanks you :)

@MangelMaxime
Copy link
Owner

MangelMaxime commented Nov 28, 2017

@alfonsogarciacaro This line seems to be failing now :)

And what I found strange is that it don't execute the function I am expecting.

If you look at the optional decoder. You can see it's using internally the value decoder which is the most basic decoder. It is use to accept any type of data and transform the express into a valid decoder type.

Problem, is the variable value at this point is undefined. I don't understand why the value decoder is not called by the code. Is it related to how Fable translate the curriedfn ?

PS: I tried to explain my observation but can be easier to just run the test and add logs into the decoder used :)

Again thanks if you take the time to take a look at this problem.

@MangelMaxime
Copy link
Owner

MangelMaxime commented Nov 28, 2017

Hum, I think I know where the error is coming from.

The probably is coming from field. When called as in the failing test, the result of:

let fieldValue = value?(fieldName) is curriedFn because value is not an object but a function.

Here is the result of value.ToString():

(...args) => {
        // _this = _this || this;
        const actualArgsLength = Math.max(args.length, 1);
        expectedArgsLength = Math.max(expectedArgsLength || f.length, 1);
        if (actualArgsLength >= expectedArgsLength) {
            const restArgs = args.splice(expectedArgsLength);
            const res = f(...args);
            if (typeof res === "function") {
                const newLambda = CurriedLambda(res);
                return restArgs.length === 0 ? newLambda : newLambda(...restArgs);
            }
            else {
                return res;
            }
        }
        else {
            return CurriedLambda((...args2) => {
                return f(...args.concat(args2));
            }, expectedArgsLength - actualArgsLength);
        }
    }

And if I execute, the function manually in the debugger I understand that's it's containing the value function.

Example result: value() --> Result {tag: 0, data: undefined}

The right value for the value variable in this case is: { "id": 67, "email": "user@mail.com" }

Yes, I admit there a lot of time "value" in this report..

So, to fix the failing test, we need to have { "id": 67, "email": "user@mail.com" } as the third argument of the field function and we should have a stable version of the Decoder.

@MangelMaxime
Copy link
Owner

Ok finally I only forget to apply andThen instead of |> on the optionalDecoder 🤦‍♂️

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

No branches or pull requests

2 participants