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

Pattern Matching [Maybe] Issue with Aff #1243

Open
jmzagorski opened this issue Aug 22, 2023 · 4 comments
Open

Pattern Matching [Maybe] Issue with Aff #1243

jmzagorski opened this issue Aug 22, 2023 · 4 comments

Comments

@jmzagorski
Copy link

I ran into a problem while unit testing my application, and wanted to get your opinion to determine if this is a bug or it behaves as expected. Really, I got lazy with unit testing on a generic method so I used object with Aff<T>.MapFail, which resulted in the Error object succeeding because the pattern matching has the generic type matched before the Error object.

public static Eff<RT, B> BiMap<RT, A, B>(this Eff<RT, A> ma, Func<A, B> Succ, Func<Error, Error> Fail) where RT : struct =>
new(rt => ma.Run(rt).Case switch
{
A x => FinSucc(Succ(x)),
Error e => FinFail<B>(Fail(e)),
_ => throw new BottomException()

Here is a simple replication:

Unit Test

public class Test
{
    [Fact]
    public async Task ShouldFail()
    {
        var error = Error.New("foobar");

        var fin = await FailAff<object>(error).MapFail(e => e).Run();

        Assert.True(fin.IsFail); // This fails
    }
}

Would you expect IsFail to be true or false?

@louthy
Copy link
Owner

louthy commented Aug 22, 2023

I'd expect it to be in a Fail state, yes. Could you step into the functions to see how it's happened? And what the actual state of the Fin is? (I'm assuming Bottom).

@louthy
Copy link
Owner

louthy commented Aug 22, 2023

Sorry, just read your comment fully. It looks like you're right that anything object would match first, so yes, that's a bug. If you want to submit a fix, I'm due to do a new release soon.

@jmzagorski
Copy link
Author

How large of a changeset would you like this to be? For example, change just that one method, or look over that file, or include other files that have the generic before the Error in pattern matching? I noticed some instances in the Eff<T> as well.

@louthy
Copy link
Owner

louthy commented Aug 23, 2023

I will accept any amount of help! If you're willing to find all of the similar issues and fix (search for '.Case'), that's awesome. If you fix this one instance, that's awesome too!

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