From b9f79fdd31fa65be79dfe714d32d8cc75e666da2 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Tue, 19 Apr 2022 13:09:40 -0400 Subject: [PATCH] Able variables through different functions compile --- compiler/can/src/def.rs | 4 ++++ compiler/test_gen/src/gen_abilities.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index 6b9c4450c5..2b981510f0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -478,6 +478,10 @@ pub fn canonicalize_defs<'a>( } }; + if pattern_type == PatternType::TopLevelDef { + env.top_level_symbols.insert(member_sym); + } + // What variables in the annotation are bound to the parent ability, and what variables // are bound to some other ability? let (variables_bound_to_ability, variables_bound_to_other_abilities): (Vec<_>, Vec<_>) = diff --git a/compiler/test_gen/src/gen_abilities.rs b/compiler/test_gen/src/gen_abilities.rs index 9b0b1f0ed5..40711c9baf 100644 --- a/compiler/test_gen/src/gen_abilities.rs +++ b/compiler/test_gen/src/gen_abilities.rs @@ -84,3 +84,26 @@ fn alias_member_specialization() { u64 ); } + +#[test] +fn ability_constrained_in_non_member_usage() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [ result ] to "./platform" + + Hash has + hash : a -> U64 | a has Hash + + mulHashes = \x, y -> hash x * hash y + + Id := U64 + hash = \$Id n -> n + + result = mulHashes ($Id 5) ($Id 7) + "# + ), + 35, + u64 + ) +}