@@ -16461,6 +16461,72 @@ mod hir_opt_tests {
1646116461 ");
1646216462 }
1646316463
16464+ #[test]
16465+ fn test_not_fold_string_equal_through_failing_guard() {
16466+ eval(r#"
16467+ # frozen_string_literal: true
16468+ class Foo
16469+ def self.bar(l, r) = l == r
16470+ end
16471+ def test(flag)
16472+ foo = Foo
16473+ if flag
16474+ foo.bar("a", "b")
16475+ else
16476+ foo.bar("a", :sym)
16477+ end
16478+ end
16479+ test(true)
16480+ test(true)
16481+ "#);
16482+ assert_snapshot!(hir_string("test"), @"
16483+ fn test@<compiled>:7:
16484+ bb1():
16485+ EntryPoint interpreter
16486+ v1:BasicObject = LoadSelf
16487+ v2:CPtr = LoadSP
16488+ v3:BasicObject = LoadField v2, :flag@0x1000
16489+ Jump bb3(v1, v3)
16490+ bb2():
16491+ EntryPoint JIT(0)
16492+ v7:BasicObject = LoadArg :self@0
16493+ v8:BasicObject = LoadArg :flag@1
16494+ Jump bb3(v7, v8)
16495+ bb3(v11:BasicObject, v12:BasicObject):
16496+ v101:NilClass = Const Value(nil)
16497+ PatchPoint StableConstantNames(0x1008, Foo)
16498+ v18:ClassSubclass[Foo@0x1010] = Const Value(VALUE(0x1010))
16499+ PatchPoint NoEPEscape(test)
16500+ v25:CBool = Test v12
16501+ v26:Falsy = RefineType v12, Falsy
16502+ CondBranch v25, bb5(), bb4()
16503+ bb5():
16504+ v28:Truthy = RefineType v12, Truthy
16505+ v32:StringExact[VALUE(0x1018)] = Const Value(VALUE(0x1018))
16506+ v34:StringExact[VALUE(0x1020)] = Const Value(VALUE(0x1020))
16507+ PatchPoint MethodRedefined(Class@0x1028, bar@0x1030, cme:0x1038)
16508+ PushInlineFrame :bar, v18 (0x1060), num_args=2
16509+ PatchPoint NoSingletonClass(String@0x1080)
16510+ PatchPoint MethodRedefined(String@0x1080, ==@0x1088, cme:0x1090)
16511+ v113:FalseClass = Const Value(false)
16512+ CheckInterrupts
16513+ PopInlineFrame
16514+ Return v113
16515+ bb4():
16516+ v48:StringExact[VALUE(0x1018)] = Const Value(VALUE(0x1018))
16517+ v50:StaticSymbol[:sym] = Const Value(VALUE(0x10b8))
16518+ PatchPoint MethodRedefined(Class@0x1028, bar@0x1030, cme:0x1038)
16519+ PushInlineFrame :bar, v18 (0x1060), num_args=2
16520+ PatchPoint NoSingletonClass(String@0x1080)
16521+ PatchPoint MethodRedefined(String@0x1080, ==@0x1088, cme:0x1090)
16522+ v111 = GuardType v50, String
16523+ v112:BoolExact = StringEqual v48, v111
16524+ CheckInterrupts
16525+ PopInlineFrame
16526+ Return v112
16527+ ");
16528+ }
16529+
1646416530 #[test]
1646516531 fn opt_neq_string_nil_falls_back_to_basic_object_neq() {
1646616532 eval(r#"
0 commit comments