From e4173cf75233e40cbb94ea29bde92ae8ccd8584d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 13 Dec 2025 15:50:01 -0500 Subject: [PATCH] Add faster eval test for issue 8664 and use unsuffixed numbers The bug only occurs with unsuffixed number literals (which default to Dec), not with suffixed ones like 8i64. Update the fx test to use unsuffixed numbers to properly reproduce the bug, and add a faster eval test that verifies the same behavior. Co-Authored-By: Claude Opus 4.5 --- src/cli/test/fx_test_specs.zig | 2 +- src/eval/test/eval_test.zig | 20 ++++++++++++++++++++ test/fx/issue8664.roc | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cli/test/fx_test_specs.zig b/src/cli/test/fx_test_specs.zig index 1300eb2fa1..51ee3e5f28 100644 --- a/src/cli/test/fx_test_specs.zig +++ b/src/cli/test/fx_test_specs.zig @@ -240,7 +240,7 @@ pub const io_spec_tests = [_]TestSpec{ }, .{ .roc_file = "test/fx/issue8664.roc", - .io_spec = "1>num: 8|1>num: 7|1>result: 7", + .io_spec = "1>num: 8.0|1>num: 7.0|1>result: 7.0", .description = "Regression test: Issue #8664 - InvalidMethodReceiver when calling methods on elements from untyped list parameter", }, }; diff --git a/src/eval/test/eval_test.zig b/src/eval/test/eval_test.zig index e89b30290b..ba72ee2849 100644 --- a/src/eval/test/eval_test.zig +++ b/src/eval/test/eval_test.zig @@ -1406,3 +1406,23 @@ test "List.len returns proper U64 nominal type for method calls - regression" { \\} , "3", .no_trace); } + +test "for loop element type extracted from list runtime type - regression #8664" { + // Regression test for InvalidMethodReceiver when calling methods on elements + // from a for loop over a list passed to an untyped function parameter. + // The fix: extract element type from list's runtime type (e.g., List(Dec)) + // instead of using the pattern's compile-time flex variable. + // Note: unsuffixed number literals default to Dec in Roc. + try runExpectStr( + \\{ + \\ calc = |list| { + \\ var $result = "" + \\ for elem in list { + \\ $result = elem.to_str() + \\ } + \\ $result + \\ } + \\ calc([1, 2, 3]) + \\} + , "3.0", .no_trace); +} diff --git a/test/fx/issue8664.roc b/test/fx/issue8664.roc index 6b9373b5f8..e035cbea8e 100644 --- a/test/fx/issue8664.roc +++ b/test/fx/issue8664.roc @@ -17,7 +17,7 @@ calc = |line| { } main! = || { - line = [8i64, 7i64, 6i64] + line = [8, 7, 6] num = calc(line) Stdout.line!("result: ${num.to_str()}") }