From 40196185a0388b9e3c0a3faaed9f41412e681796 Mon Sep 17 00:00:00 2001 From: ayazhafiz Date: Sun, 6 Feb 2022 20:58:13 -0500 Subject: [PATCH] Specialize zero-argument thunks with the correct variable Previously we would pass the annotation down as the type-to-be-monomorphized for, but that would just mean the annotation would unify with itself. We instead want to use the variable the thunk is being used as to be the one unified with the thunk's annotation. Closes #2445 Closes #2446 --- compiler/mono/src/ir.rs | 3 +-- compiler/test_gen/src/gen_tags.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 436212ba2e..3c736435d9 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -2941,8 +2941,7 @@ fn specialize_naked_symbol<'a>( symbol: Symbol, ) -> Stmt<'a> { if procs.is_module_thunk(symbol) { - let partial_proc = procs.get_partial_proc(symbol).unwrap(); - let fn_var = partial_proc.annotation; + let fn_var = variable; // This is a top-level declaration, which will code gen to a 0-arity thunk. let result = call_by_name( diff --git a/compiler/test_gen/src/gen_tags.rs b/compiler/test_gen/src/gen_tags.rs index b4abaf711f..89251ac981 100644 --- a/compiler/test_gen/src/gen_tags.rs +++ b/compiler/test_gen/src/gen_tags.rs @@ -1449,3 +1449,28 @@ fn issue_2365_monomorphize_tag_with_non_empty_ext_var_wrapped_nested() { u8 ) } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn issue_2445() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ main ] to "./platform" + + none : [ None, Update a ] + none = None + + press : [ None, Update U8 ] + press = none + + main = + when press is + None -> 15 + Update _ -> 25 + "# + ), + 15, + i64 + ); +}