Skip to content

fix: wrap go interface returns as option#458

Merged
ivov merged 1 commit into
mainfrom
wrap-nilable-interface-returns
May 19, 2026
Merged

fix: wrap go interface returns as option#458
ivov merged 1 commit into
mainfrom
wrap-nilable-interface-returns

Conversation

@ivov

@ivov ivov commented May 19, 2026

Copy link
Copy Markdown
Owner

Go functions and methods returning an interface now correctly bind as Option<T>, reflecting the fact that any Go interface value can be nil. Previously Lisette claimed the result was always present, so a caller could deref into a runtime panic with no protection from the type checker.

import "go:image"

fn first_pixel(img: image.Image) -> string {
  match img.At(0, 0) {
    Some(c) => "got color",
    None => "no pixel",
  }
}

The same change applies to function returns where the body has a return nil path, such as container/ring.New(0) and math/big.Int.ModInverse.

For well-known constructors that never return nil in practice but whose multi-path bodies cannot be statically narrowed, explicit allowlist entries in bindgen.stdlib.json keep the original non-Option binding.

Close #438

@ivov ivov merged commit 79892a4 into main May 19, 2026
13 checks passed
@ivov ivov mentioned this pull request May 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Released in lisette-v0.2.8

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bindgen producing incorrect bindings

1 participant