8000 private method in a make block: uncallable from sibling methods, callable from outside the block · Issue #281 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

private method in a make block: uncallable from sibling methods, callable from outside the block #281

Closed

Description

@akoskovacs

Found while migrating rodolfo's examples/library to one module per file. Toolchain: kex 0.4.0-beta.2 (6ccdf35).

Two facets, same area — private inside a make block behaves exactly inverted from what docs/modules.md promises ("private in a make block — only callable within that make"):

1. A private make-method cannot be called from a sibling method in the same block

# src/thing.kex
module Thing

record Thing do
  name : String
end

make Thing do
  shouted :> String
  let shouted = decorate(@name)

  private do
    decorate : String -> String
    let decorate(text) = "${text}!"
  end
end
# src/main.kex
using Thing, only: [Thing]
main do
  IO.printLine(Thing { name: "kex" }.shouted)
end

kex -R --source-root src src/main.kex:

error: could not compile Kex.Thing: {error,
                                     [{"Kex.Thing",
                                       [{none,core_lint,
                                         {undefined_function,
                                          {decorate,1},
                                          {shouted,1}}}]}],
                                    []}

The call passes the type checker and fails at Core Erlang lint: the private method is apparently not emitted as a function the sibling can reach.

2. A private make-method is callable from another module's make block

# src/thing.kex
module Thing

record Thing do
  name : String
end

make Thing do
  private do
    secret :> String
    let secret = @name
  end
end
# src/uses.kex
module Uses

using Thing, only: [Thing]

make [Thing] do
  firsts :> [String]
  let firsts = this.map { |thing| thing.secret }
end
# src/main.kex
using Thing, only: [Thing]
using Uses

main do
  IO.printLine("${[Thing { name: \"x\" }].firsts}")
end

Prints [x] — the private method secret is reached from a different module's make block, which the docs forbid.

Workaround

Helpers that a make-method needs go in a module-level private do ... end block instead; module-private functions are callable from make-methods in the same module:

make Thing do
  shouted :> String
  let shouted = decorate(@name)
end

private do
  decorate : String -> String
  let decorate(text) = "${text}!"
end

Activity

  1. added this to the 0.4.0 milestone on Sep 5, 2026
  2. akoskovacs commented on Sep 7, 2026

    @akoskovacs
    CollaboratorAuthor

    Verified fixed on current main. Facet 1: a private make-method (decorate) is callable from a sibling method (shouted) — compiles and prints on interpreter and BEAM. Facet 2: reaching secret from another module's make block is now rejected at check time: ``secretis private tomake Thing.Thing` in `Thing` — it is only callable inside that block`, matching docs/modules.md.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0