8000 A trait default calling a requirement by its bare name fails on BEAM: unbound variable · Issue #759 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

A trait default calling a requirement by its bare name fails on BEAM: unbound variable #759

Open

Description

@akoskovacs

A trait default that calls one of the trait's own requirements by its bare name passes the checker and runs on the walker. On BEAM it does not compile: the lowering emits the name as an unbound variable.

trait Named do
  name :> String

  let shout = name.upperCase
end

record Dog do
  id : Integer = 0
end

make Dog, implement: Named do
  let name = "rex"
end

main do
  IO.printLine(Dog {}.shout)
end
$ kex -C min.kex
No errors found.
$ kex -R min.kex
REX
$ kex min.kex
kex_min: unbound variable 'Name' in shout/1
error: erlc failed

The emitted Core Erlang for shout/1 passes Name as a variable instead of calling name on the receiver:

'shout'/1 =
  fun (_Arg0) ->
    case <_Arg0> of
      <This> when ... is_record(This, 'Dog', 2) ... ->
        call 'kex_prelude':'upperCase'(Name)

Writing this.name.upperCase works on both backends.

This is the example in plugins/kex/skills/kex/SKILL.md ("Types, records and traits": let shout = label.upperCase), so the guide kex --skill prints teaches a program that fails under the default kex file.kex. skill_test did not catch it because it runs the guide's examples with --run-walker only (tests/skill_test.cxx:144); filed separately.

Kex 0.4.0-rc.4 (294556f), macOS arm64, OTP 29.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0