Skip to content

Hosted code (ScriptEngine.Execute) gets pre-3.4 backtrace labels: 'many', 'block in #', no '<main>' #158

Closed

Description

@Largo

Code run through the hosting API (ScriptEngine.Execute, ScriptSource.Compile(...).Run, which is also how IronRuby.Tests runs its snippets) gets backtrace labels in the old format. The same code run with ir already matches CRuby 4.0.

def many
  raise ArgumentError, 'x'
end

class Foo
  def bar = many
  def self.baz = new.bar
end

begin
  [1].each { Foo.baz }
rescue => e
  puts e.backtrace
end

CRuby 4.0.9 and ir (master, net10.0) print the same:

labels.rb:2:in 'Object#many'
labels.rb:6:in 'Foo#bar'
labels.rb:7:in 'Foo.baz'
labels.rb:11:in 'block in <main>'
labels.rb:11:in 'Array#each'
labels.rb:11:in '<main>'

Run as a hosted snippet (seen in IronRuby.Tests while working on #132), user-defined methods are unqualified, the top-level block is block in #, and the top-level frame has no label at all. Core methods are still qualified:

Backtrace9x.rb:3:in 'many'
Backtrace9x.rb:7:in 'caller_of_many'
Backtrace9x.rb:12:in 'block in #'
Backtrace9x.rb:10:in 'Integer#times'
Backtrace9x.rb:10

Where it comes from: AstGenerator.TopLevelFrameLabel returns <main> only for TopScopeFactoryKind.Main (and <top (required)> for files). The hosted kinds fall through to RubyStackTraceBuilder.TopLevelMethodName (#). The unqualified method labels likely come from the same top-level-kind distinction.

To do: give hosted top-level code CRuby's labels: qualified method labels and <main> / block in <main>, unless there is a reason a host should see something else. Then update the IronRuby.Tests expectations that rely on the old format (Backtrace*, any test that matches in 'name' or a bare file.rb top-level frame). Backtrace9's regex, for example, reads many and Backtrace9.rb.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions