Skip to content

Hosted top-level alias/undef/visibility/define_method still act only on main's singleton class #177

Closed

Description

@Largo

Left over from #174 (which fixed #163).

Since #174, in a scope-bound hosted run (ScriptCode.Run(Scope), Engine.Execute(code, scope), ScriptSource.Execute(scope)), a top-level def defines the method on main's singleton class and on Object, as CRuby does. Other top-level method-table operations still act only on main's singleton class:

  • top-level alias / alias_method
  • top-level undef / undef_method
  • public / private with method names at the top level
  • main.define_method

So, for example, after Execute("def foo = 1; alias bar foo", scope), a call to bar from inside a class raises NameError, while in CRuby it works. ir is not affected, because its top level is not scope-bound.

Also from #163's side note, still open: in hosted top-level code, def self.x is labelled Object#x in backtraces, where CRuby prints x. The label is computed in four places from the declaring module alone, and those places don't know whether the def had an explicit target.

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Nov 9, 2026
    2628ecc
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