Pattern matching Success
containing an array returns a surprising result
#158
Labels
Success
containing an array returns a surprising result
#158
Describe the bug
When you pattern match a
Result
that happens to contain an array in acase
statement, the destructured contents of theResult
contains the contents of the array, not the array.We discovered this because we have a function that decodes JSON and returns the contents in a
Result
(Success
if it parsed correctly,Failure
if it didn't). We don't know ahead of time whether or not theResult
will contain an array or not. It's not really a problem to use an if statement in this situation (result.value!
contains the correct value), but it's very surprising that you have to.To Reproduce
Returns 42
If instead you set:
result = Success([1, 2, 3, 4])
The above case statement will generate a
NoMatchingPatternError
.Expected behavior
The case statement should return
[42]
(or in the second instance[1, 2, 3, 4]
)My environment
The text was updated successfully, but these errors were encountered: