Skip to content

String#+ with a non-String raises NoMethodError instead of TypeError #409

Open

Description

@linyiru

Found while writing the #391 fixtures (verified 2026-09-27 on 64326cb against CRuby 3.4.8).

begin; "s" + 1; rescue => e; puts e.class; end
output
CRuby 3.4.8 TypeError (no implicit conversion of Integer into String)
rubyrs NoMethodError

It looks like String#+ tries to_str on its argument and lets the resulting NoMethodError escape, where it should convert that into TypeError. The same coercion path (rb_str_to_str / implicit to_str) is probably shared by other String methods (<<, concat, start_with?, ...) and should be checked with them. method_missing_lite_serve.rb uses nil + 1 for its deopt case instead of "s" + 1 because of this.

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions