Skip to content

String interpolation of BasicObject object raises NameError instead of NoMethodError #9222

Description

@trinistr

Environment Information

  • jruby 10.0.3.0-SNAPSHOT (3.4.5) 2025-11-30 ffffffffff OpenJDK 64-Bit Server VM 21.0.9+10 on 21.0.9+10 +indy +jit [x86_64-linux] (latest master)
  • Linux 6.18.4-1-MANJARO #1 SMP PREEMPT_DYNAMIC Thu, 08 Jan 2026 12:46:08 +0000 x86_64 GNU/Linux

Expected Behavior

Given this file a.rb:

A = Class.new(BasicObject)

and running:

jruby -r ./a -e '"#{A.new}"'

I expect NoMethodError: undefined method 'to_s' for an instance of A.

Actual Behavior

Instead, NameError is raised: NameError: undefined local variable or method 'to_s' for an instance of A.

Additional information

  1. Doing interpolation in the same context, like one file or an IRB session, raises NoMethodError. Separate file is required.
  2. Explicitly calling "#{A.new.to_s}" raises NoMethodError as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions