plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
b6a9042
— Peter John
2026-07-20T20:16:17+05:30
test(plum-wasm-codegen): cover same bare-generic-enum-param function at multiple instantiations
plum-wasm-codegen/tests/codegen_tests.rs
CHANGED
|
@@ -813,6 +813,32 @@ main() -> Int =
|
|
|
813
813
|
assert_eq!(run_main(&bytes), 17);
|
|
814
814
|
}
|
|
815
815
|
|
|
816
|
+
#[test]
|
|
817
|
+
fn same_bare_generic_enum_param_function_called_multiple_times_runs_correctly() {
|
|
818
|
+
// Regression test: the same generic function taking a bare generic-enum-typed param,
|
|
819
|
+
// called at the same concrete instantiation multiple times, must correctly specialize
|
|
820
|
+
// and reuse that specialization. This tests that the mangling logic for `unwrapOr`
|
|
821
|
+
// produces identical specialized code on both call sites, not aliased/incorrect code.
|
|
822
|
+
let src = "\
|
|
823
|
+
enum Option =
|
|
824
|
+
| Some(a)
|
|
825
|
+
| None
|
|
826
|
+
|
|
827
|
+
unwrapOr(o: Option, default: Int) -> Int =
|
|
828
|
+
match o
|
|
829
|
+
Some(v) =>
|
|
830
|
+
v
|
|
831
|
+
None =>
|
|
832
|
+
default
|
|
833
|
+
|
|
834
|
+
main() -> Int =
|
|
835
|
+
unwrapOr(Some(5), 0) + unwrapOr(Some(37), 0)
|
|
836
|
+
";
|
|
837
|
+
let source = parse(src);
|
|
838
|
+
let bytes = compile_source(&source).expect("compile failed");
|
|
839
|
+
assert_eq!(run_main(&bytes), 42);
|
|
840
|
+
}
|
|
841
|
+
|
|
816
842
|
#[test]
|
|
817
843
|
fn ordinary_function_with_bare_generic_class_param_runs_correctly() {
|
|
818
844
|
let src = "\
|