@@ -596,8 +596,22 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
596596 self . env . enter_type ( name. node , Type :: Var ( TyVar :: from_symbol ( name. node ) ) ) ;
597597 }
598598
599- for & WithPos { node : TypeDec { ref name, ref ty, .. } , .. } in type_declarations {
599+ for & WithPos { node : TypeDec { ref name, ref ty, ref ty_vars, .. } , .. } in type_declarations {
600+ let has_type_args = !ty_vars. idents . is_empty ( ) ;
601+ if has_type_args {
602+ self . env . begin_type_scope ( ) ;
603+ }
604+ let mut type_vars = vec ! [ ] ;
605+ for var in & ty_vars. idents {
606+ let type_var = self . new_type_var ( ) ;
607+ type_vars. push ( type_var) ;
608+ self . env . enter_type ( var. node , Type :: Var ( type_var) ) ;
609+ }
610+
600611 let new_type = self . trans_ty ( name. node , ty) ;
612+ if has_type_args {
613+ self . env . end_type_scope ( ) ;
614+ }
601615 self . env . enter_type ( name. node , new_type) ;
602616 }
603617 None
@@ -1407,6 +1421,7 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
14071421 match ty. node . typ . node {
14081422 InnerType :: Array { ref ident } => {
14091423 let ty = self . get_type ( ident, AddError ) ;
1424+ // FIXME: according to the book, the Unique should be at the outermost.
14101425 Type :: App ( TypeConstructor :: new_unique ( TypeConstructor :: Array ) , vec ! [ ty] )
14111426 } ,
14121427 InnerType :: Function { ref parameters, ref return_type } => {
@@ -1506,6 +1521,10 @@ impl<'a, F: Clone + Debug + Frame + PartialEq> SemanticAnalyzer<'a, F> {
15061521 ( fields, data_layout, parent_methods)
15071522 }
15081523
1524+ fn new_type_var ( & mut self ) -> TyVar {
1525+ TyVar :: from_symbol ( self . symbols . unnamed ( ) )
1526+ }
1527+
15091528 fn duplicate_param ( & mut self , param : & FieldWithPos ) {
15101529 let ident = self . env . var_name ( param. node . name ) ;
15111530 self . add_error ( Error :: DuplicateParam {
0 commit comments