Skip to content

Commit

Permalink
Row polymorphic variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Dec 9, 2018
1 parent a748a67 commit 203f7a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions check/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,13 @@ impl<'a> Typecheck<'a> {
self.translate_ast_type(&type_cache, typ)
});

if let Type::Variant(ref row) = **alias.unresolved_type().remove_forall() {
for field in row.row_iter() {
let symbol = self.symbols.scoped_symbol(field.name.as_ref());
self.original_symbols.insert(field.name.clone(), symbol);
}
}

// alias.unresolved_type() is a dummy in this context
self.named_variables.extend(
alias
Expand All @@ -1994,6 +2001,7 @@ impl<'a> Typecheck<'a> {

let replacement = self.create_unifiable_signature2(alias.unresolved_type());


if let Some(typ) = replacement {
*alias.unresolved_type_mut() = typ;
}
Expand Down
20 changes: 20 additions & 0 deletions check/tests/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,23 @@ fn consider_the_type_of_the_splat_record() {

assert_req!(result.map(|t| t.to_string()), Ok("{ x : Int, y : Int }"));
}

#[test]
fn polymorphic_variants() {
let _ = env_logger::try_init();

let text = r#"
type AA r = (| A Int .. r)
type BB r = (| B String .. r)
if True then
A 123
else
B "abc"
"#;
let result = support::typecheck(text);

assert_req!(
result.map(|t| t.to_string()),
Ok("forall a . | test.A Int | test.B String | a")
);
}

0 comments on commit 203f7a8

Please sign in to comment.