Apologies for the title, I can't figure out what's going on to give a better name.
In the below snippet I seem to get an <opaque> type when I print the value of v, even though if it matches we know it must be a string from the type declaration of val. Seems to segfault (status 139) after the v=="2" comparison. Equivalent issue if using a U64 etc, not just with Str.
(Compiler: debug-a3741118, mac apple silicon)
print! = |something| {
Stdout.line!(Str.inspect(something))
}
main! = |_args| {
val : [Nothing, Just(U64, Str)]
val = ["2"]->find_first(|v| v == "2")
_newval = match val {
Just(_, v) => {
# Matches, then:
print!(v) # Prints: <opaque> even though it's a Str?
print!((v == "2")) # Nothing printed
print!("Echo") # Nothing printed
v
}
Nothing => {
"Something else"
}
}
Ok({})
}
find_first : List(v), (v -> Bool) -> [Just(U64, v), Nothing]
find_first = |l, pred| {
var $found = Nothing
var $index = 0
for el in l {
if pred(el) {
$found = Just($index, el)
break
}
$index = $index + 1
}
$found
}
Ah, switching out the multi-payload tag Just(U64, v) for Just({index: U64, value: v}) seems to fix it.
I get a "panic: reached unreachable code" in addition to the rest, I have created #9229 for this.
Last updated: Mar 20 2026 at 12:28 UTC