Skip to content

A one-line method body that is a struct literal parses as a braced block inside extend #2998

Closed

Description

@ehartford
type P { a: i32, b: i32 }
type S { n: i32 }
extend S:
    fn pair(x: i32): P { a: x, b: self.n }
fn free(a: i32): P { a, b: 1 }      // fine
let s = S { n: 2 }
print(s.pair(1).b)
error: unknown field 'b' for type 'Unit'

Inside extend (and presumably impl), fn name(args): Type { … } reads the { as a braced body, so the method returns Unit; the same one-line body on a free function parses as the struct literal. §29.13's inline-colon form is the least-ceremony spelling for a constructor-like method (the mission's style rule: "inline the colon when the body is very small"), so a method cannot be written the way a free function can. Found rewriting examples/service (make_profile, build). Expected: the body after : is an expression, and a Name { that names a type is the literal, in a method as in a function.

Activity

  1. added
    spec-gap
    on Nov 3, 2026
  2. added a commit that references this issue on Nov 5, 2026
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

    spec-gap

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions