Skip to content

[bug]: FlatMap implementation in fn package is inverted #10401

@gijswijs

Description

@gijswijs

Pre-Submission Checklist

  • I have searched the existing issues and believe this is a new bug.
  • I am not asking a question about how to use lnd, but reporting a bug (otherwise open a discussion).

LND Version

v0.20.0 and all versions before with the fn package

LND Configuration

--

Backend Version

na

Backend Configuration

na

OS/Distribution

na

Bug Details & Steps to Reproduce

The implementation of the FlatMap method for the Result type is inverted:

lnd/fn/result.go

Lines 148 to 156 in 85a5bf2

// FlatMap applies a kleisli endomorphic function that returns a Result to the
// success value if it exists.
func (r Result[T]) FlatMap(f func(T) Result[T]) Result[T] {
if r.IsOk() {
return r
}
return f(r.left)
}

For a Result[T], FlatMap should apply f when the result is Ok, and propagate the error unchanged when it’s Err. The current code returns r on Ok and tries to use r.left when Err, which is wrong.

Expected Behavior

na

Debug Information

No response

Environment

No response

Metadata

Metadata

Assignees

Labels

bugUnintended code behaviour

Type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions