Issue #17104 has been updated by Eregon (Benoit Daloze). mame (Yusuke Endoh) wrote in #note-18: > I found `"foo#{ "foo" }"` frozen because it is optimized to `"foofoo"` at the parser. What do you think? I guess that's semantically correct (besides the frozen status), since interpolation does not need to call `#to_s` for a String. Since such code is very unlikely to appear in real code, I think it ultimately does not matter too much. But if we can easily remove that optimization in the parser, I think it would be better, because this is an inconsistency (it makes it harder to reason about Ruby semantics & it breaks referential transparency) and optimizing `"foo#{ "foo" }"` seems to have no use in practice. Could you point me to where the optimization is done in the parser if you found it? :) ---------------------------------------- Feature #17104: Do not freeze interpolated strings when using frozen-string-literal https://bugs.ruby-lang.org/issues/17104#change-87347 * Author: bughit (bug hit) * Status: Open * Priority: Normal * Assignee: Eregon (Benoit Daloze) ---------------------------------------- I think the point of frozen string literals is to avoid needless allocations. Interpolated strings are allocated each time, so freezing them appears pointless. ```rb #frozen_string_literal: true def foo(str) "#{str}" end fr1 = 'a' fr2 = 'a' fr1_1 = foo(fr1) fr2_1 = foo(fr2) puts fr1.__id__, fr2.__id__, fr1_1.__id__, fr2_1.__id__ puts fr1_1 << 'b' ``` -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>