Skip to content

codegen: a function returning Option[Unit] fails — return type mismatch at call site (struct{i32,i32} vs struct{i32}) #1218

Closed

Description

@ehartford

Spec. §3.4 / §9: `Option[T]` is generic over any `T`, including `Unit`.

Repro (main at 3811221, installed v0.15.2.1):

```
fn gate(open: bool) -> Option[Unit]:
if open: Some(()) else: None
fn main:
match gate(true):
Some(_) => print("some")
None => print("none")
```

Actual.
```
error: return type mismatch at call site actual=struct{i32,i32} expected=struct{i32} fn=main
error: code generation failed
```

Expected. prints `some`. The callee's declared return layout drops the zero-sized payload (`struct{i32}`) while the call site keeps a slot for it (`struct{i32,i32}`): two derivations of one type's layout.

Loud, not a miscompile. Found while testing `?` over Unit payloads (`Result[Unit, E]?` crashed the compiler in LLVM; fixed separately). `Result[Unit, E]` as a return type works.

Workaround used. None; the `?` test covers `Result[Unit, E]` only and should gain `Option[Unit]` when this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions