From 3da04b97866631ca134026388b226eda92a9549e Mon Sep 17 00:00:00 2001 From: Tsutomu Katsube Date: Sat, 19 Oct 2024 02:15:22 +0900 Subject: [PATCH] Suppress "literal string will be frozen in the future" warning (#1019) * 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 --------- Co-authored-by: tomoya ishida --- lib/irb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irb.rb b/lib/irb.rb index 12eb69c5b..528892797 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -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)