From 453b2336518c085813804354bb07541f481fd27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efe=20G=C3=B6kdemir?= Date: Sun, 8 Nov 2026 16:27:03 +0300 Subject: [PATCH] ZJIT: annotate Regexp#to_s return type Record Regexp#to_s as returning StringExact so HIR can retain the precise result type. Fixes #1108. --- zjit/src/cruby_methods.rs | 1 + zjit/src/hir/opt_tests.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/zjit/src/cruby_methods.rs b/zjit/src/cruby_methods.rs index 0eff229ea26129..b164f6620c0e09 100644 --- a/zjit/src/cruby_methods.rs +++ b/zjit/src/cruby_methods.rs @@ -281,6 +281,7 @@ pub fn init() -> Annotations { annotate!(rb_cInteger, ">>", inline_integer_rshift); annotate!(rb_cInteger, "[]", inline_integer_aref); annotate!(rb_cInteger, "to_s", types::StringExact); + annotate!(rb_cRegexp, "to_s", types::StringExact); annotate!(rb_cFloat, "+", inline_float_plus); annotate!(rb_cFloat, "-", inline_float_minus); annotate!(rb_cFloat, "*", inline_float_mul); diff --git a/zjit/src/hir/opt_tests.rs b/zjit/src/hir/opt_tests.rs index 8c9edcec431b8e..edad4e138f95f7 100644 --- a/zjit/src/hir/opt_tests.rs +++ b/zjit/src/hir/opt_tests.rs @@ -14198,6 +14198,24 @@ mod hir_opt_tests { "); } + #[test] + fn test_regexp_to_s_returns_string() { + eval(r#" + def test(regexp) = regexp.to_s + test /pattern/ + "#); + + let hir = hir_string("test"); + let regexp_to_s_call = hir + .lines() + .find(|line| line.contains(":Regexp#to_s")) + .expect("expected a Regexp#to_s call in HIR"); + assert!( + regexp_to_s_call.contains("StringExact"), + "expected Regexp#to_s to return StringExact, got: {regexp_to_s_call}" + ); + } + #[test] fn test_bignum_to_s_returns_string() { eval(r#"