You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sema (§10.7, D165): List.traverse does not propagate expected Option[List[U]] / Result[List[U], E] return demand into its closure #3042
Found during the #2987 manual audit of docs/spec/010_errors.md (§10.7, lines 342–349).
Minimal reproduction
fn main:
let names = ["1", "2", "3"]
let parsed: Option[List[i32]] = names.traverse(s => s.parse())
print(parsed.unwrap().len())
Actual
error: List.traverse() function must return Option or Result
--> repro.w:3:37
3 | let parsed: Option[List[i32]] = names.traverse(s => s.parse())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: cannot infer generic method type parameter 'T'
--> repro.w:3:57
3 | let parsed: Option[List[i32]] = names.traverse(s => s.parse())
| ^^^^^^^^^
Expected
When List.traverse has surrounding expected type Option[List[U]] or Result[List[U], E], Sema propagates Option[U] / Result[U, E] as the closure's expected return type so return-type-polymorphic expressions inside the closure (s.parse(), D165) infer U without an explicit (s) -> Option[i32] => return annotation.
Activity
#3038, #3039, #3041, #3042, #2958: five spec-gap fixes from the #2987 …