mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Add test gen for multimorphic capture
This commit is contained in:
parent
8be230695b
commit
ada4b0ea43
3 changed files with 49 additions and 1 deletions
|
@ -2599,9 +2599,20 @@ fn finish_specialization(
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.into_module_ids();
|
.into_module_ids();
|
||||||
|
|
||||||
|
let mut all_ident_ids = state.constrained_ident_ids;
|
||||||
|
let multimorphic_idents = state
|
||||||
|
.multimorphic_names
|
||||||
|
.try_unwrap_names()
|
||||||
|
.expect("There were still outstanding Arc references to multimorphic_names");
|
||||||
|
let old_idents = all_ident_ids.insert(ModuleId::MULTIMORPHIC, multimorphic_idents);
|
||||||
|
debug_assert!(
|
||||||
|
old_idents.is_none() || old_idents.unwrap().is_empty(),
|
||||||
|
"duplicate multimorphic idents"
|
||||||
|
);
|
||||||
|
|
||||||
let interns = Interns {
|
let interns = Interns {
|
||||||
module_ids,
|
module_ids,
|
||||||
all_ident_ids: state.constrained_ident_ids,
|
all_ident_ids,
|
||||||
};
|
};
|
||||||
|
|
||||||
let State {
|
let State {
|
||||||
|
|
|
@ -852,6 +852,16 @@ impl MultimorphicNames {
|
||||||
fn insert<'b>(&mut self, name: Symbol, captures_layouts: &'b [Layout<'b>]) -> Symbol {
|
fn insert<'b>(&mut self, name: Symbol, captures_layouts: &'b [Layout<'b>]) -> Symbol {
|
||||||
self.0.lock().unwrap().insert(name, captures_layouts)
|
self.0.lock().unwrap().insert(name, captures_layouts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Assumes there is only one clone still alive.
|
||||||
|
/// If there is more than one clone alive, `self` is returned.
|
||||||
|
pub fn try_unwrap_names(self) -> Result<IdentIds, Self> {
|
||||||
|
let mutex = Arc::try_unwrap(self.0).map_err(Self)?;
|
||||||
|
let table = mutex
|
||||||
|
.into_inner()
|
||||||
|
.expect("how can there be another lock if we consumed the only ref?");
|
||||||
|
Ok(table.ident_ids)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
|
|
|
@ -3498,3 +3498,30 @@ fn polymorphic_lambda_captures_polymorphic_value() {
|
||||||
u64
|
u64
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(any(feature = "gen-llvm"))]
|
||||||
|
fn multimorphic_lambda_set_u64_vs_u8_capture() {
|
||||||
|
assert_evals_to!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
capture : _ -> ({} -> Str)
|
||||||
|
capture = \val ->
|
||||||
|
\{} ->
|
||||||
|
Num.toStr val
|
||||||
|
|
||||||
|
x : [True, False]
|
||||||
|
x = True
|
||||||
|
|
||||||
|
fun =
|
||||||
|
when x is
|
||||||
|
True -> capture 123u64
|
||||||
|
False -> capture 18u8
|
||||||
|
|
||||||
|
fun {}
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
RocStr::from("123"),
|
||||||
|
RocStr
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue