Repository: gluon-lang/gluon (rust)

Issue:
Pattern matching error on type aliases
First of all, thanks for the amazing work on Gluon - I've just starting playing with it, and I'm pretty excited about its potential.

I found an unexpected case where pattern matching doesn't work if the type is a type alias.
e.g.
```
type MyType = (String, Int)

let getName thing : MyType -> String =
    let (name, count) = thing
    name
```
This compiles fine (according to the language server anyway), but fails when run with "Undefined variable `name`".
If, however the function is defined as
```
let getName thing : (String, Int) -> String =
    let (name, count) = thing
    name
```
it works. I would expect these to be equivalent.
Gluon version 0.11.2

Pull request description:
fix(compiler): Don't panic when matching a tuple against an alias
Fixes #749

Patch:
diff --git a/vm/src/core/mod.rs b/vm/src/core/mod.rs
index 8091bcb9..da530359 100644
--- a/vm/src/core/mod.rs
+++ b/vm/src/core/mod.rs
@@ -1675,6 +1675,8 @@ impl<'a, 'e> PatternTranslator<'a, 'e> {
                     }
                 }
                 ast::Pattern::Tuple { ref typ, ref elems } => {
+                    let typ = remove_aliases_cow(&self.0.env, &mut NullInterner, typ);
+
                     for (i, (elem, field_type)) in elems.iter().zip(typ.row_iter()).enumerate() {
                         if !add_duplicate_ident(
                             &mut replacements,


Test patch:
diff --git a/tests/pattern_match.rs b/tests/pattern_match.rs
index 3d5091e0..1d6079a1 100644
--- a/tests/pattern_match.rs
+++ b/tests/pattern_match.rs
@@ -188,3 +188,17 @@ match (Some 10, 1) with
 "#,
 10
 }
+
+test_expr! {
+pattern_match_tuple_alias,
+r#"
+type MyType = (String, Int)
+
+let getName thing : MyType -> String =
+    let (name, count) = thing
+    name
+
+getName ("abc", 123)
+"#,
+"abc".to_string()
+}