Skip to content

Commit

Permalink
Suppress "literal string will be frozen in the future" warning (#1019)
Browse files Browse the repository at this point in the history
* Suppress "literal string will be frozen in the future" warning

Before change:

```console
$ ruby -W -I lib -e 'require "irb"; IRB.setup(nil); IRB::Irb.new.build_statement("1 + 2")'
/Users/zzz/src/github.com/ruby/irb/lib/irb.rb:1135: warning: literal string will be frozen in the future
```

After change:

```console
$ ruby -W -I lib -e 'require "irb"; IRB.setup(nil); IRB::Irb.new.build_statement("1 + 2")'
```

* Making build_statement not modify the given argument

Because improves readability and code quality.

Co-authored-by: tomoya ishida <[email protected]>

---------

Co-authored-by: tomoya ishida <[email protected]>
  • Loading branch information
tikkss and tompng authored Oct 18, 2024
1 parent db0a923 commit 3da04b9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ def build_statement(code)
return Statement::EmptyInput.new
end

code.force_encoding(@context.io.encoding)
code = code.dup.force_encoding(@context.io.encoding)
if (command, arg = @context.parse_command(code))
command_class = Command.load_command(command)
Statement::Command.new(code, command_class, arg)
Expand Down

0 comments on commit 3da04b9

Please sign in to comment.