8000 Trait default methods (any?, all?, ==) don't dispatch for opt-in stdlib types on BEAM · Issue #235 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Trait default methods (any?, all?, ==) don't dispatch for opt-in stdlib types on BEAM #235

Closed

Description

@akoskovacs

Summary

Discovered while fixing #233. Data.Set/Data.Stack/Data.Queue/Data.UnorderedSet all implement Enumerable/Foldable (whose any?/all?/etc. are trait DEFAULT methods derived from reduce), and Queue overloads ==. On BEAM, calling these trait-provided methods fails outright rather than falling back to the derived implementation.

Repro

using Data.Stack

main do
  let s = Stack.from([1, 2, 3])
  IO.printLine("${s.any? { |x| x > 2 }}")
end

Run with ./build/kex -R → Undefined method: any? for Data.Stack.

Also seen:

  • spec/stdlib/data_set.spec.kex: Foldable queries come for free → Undefined method: any? for Data.Set
  • spec/stdlib/data_stack.spec.kex: same, for Data.Stack
  • spec/stdlib/data_queue.spec.kex: Foldable queries come for free → Undefined method: any? for Data.Queue, and separately peek answers the front element → Undefined method: == for Option<Int> (comparing Queue.from([1,2,3]).peek to Just(1))

The tree-walk interpreter is unaffected — make spec-stdlib passes cleanly for all of these; only -c/-R fail.

Likely area

Trait default-method inheritance for a make Type, implement: Trait do ... end block is handled somewhere in src/ir/lower.cxx's trait-splicing pass (mentioned near lowerMakeGroup/inheritedDefaults — "a make Type, implement: T do ... end block inherits every default method ... of each T it doesn't override itself"). Given this is the first time an OPT-IN, SOURCE-LOADED module (rather than a prelude-tier type) implements Enumerable/Foldable purely via inherited defaults with no local override, this path may simply not have been exercised for that combination before.

Related: #229, #233 (the module-alias fix that exposed this), #234 (a second, separate lowering bug found in the same investigation).

🤖 Generated with Claude Code

https://claude.ai/code/session_01SbX7B795iGL8Tc66wngUxC

Activity

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

      0