fn translate_type(&mut self, ty: &EA::Type) -> Type {
        use EA::Type_::*;
        match &ty.value {
            Apply(access, args) => {
                if let EA::ModuleAccess_::Name(n) = &access.value {
                    let check_zero_args = |et: &mut Self, ty: Type| {
                        if args.is_empty() {
                            ty
                        } else {
                            et.error(&et.to_loc(&n.loc), "expected no type arguments");
                            Type::Error
                        }
                    };
                    // Attempt to resolve as builtin type.
                    match n.value.as_str() {
                        "bool" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Bool));
                        }
                        "u8" => return check_zero_args(self, Type::new_prim(PrimitiveType::U8)),
                        "u64" => return check_zero_args(self, Type::new_prim(PrimitiveType::U64)),
                        "u128" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::U128));
                        }
                        "num" => return check_zero_args(self, Type::new_prim(PrimitiveType::Num)),
                        "range" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Range));
                        }
                        "address" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Address));
                        }
                        "signer" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Signer));
                        }
                        "type" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::TypeValue));
                        }
                        "vector" => {
                            if args.len() != 1 {
                                self.error(
                                    &self.to_loc(&ty.loc),
                                    "expected one type argument for `vector`",
                                );
                                return Type::Error;
                            } else {
                                return Type::Vector(Box::new(self.translate_type(&args[0])));
                            }
                        }
                        _ => {}
                    }
                    // Attempt to resolve as a type parameter.
                    let sym = self.symbol_pool().make(n.value.as_str());
                    if let Some(ty) = self.type_params_table.get(&sym).cloned() {
                        return check_zero_args(self, ty);
                    }
                    // Attempt to resolve as a type value.
                    if let Some(entry) = self.lookup_local(sym, false) {
                        let ty = entry.type_.clone();
                        self.check_type(
                            &self.to_loc(&n.loc),
                            &ty,
                            &Type::new_prim(PrimitiveType::TypeValue),
                            "in type",
                        );
                        return check_zero_args(self, Type::TypeLocal(sym));
                    }
                }
                let loc = self.to_loc(&access.loc);
                let sym = self.parent.module_access_to_qualified(access);
                let rty = self.parent.parent.lookup_type(&loc, &sym);
                if !args.is_empty() {
                    // Replace type instantiation.
                    if let Type::Struct(mid, sid, params) = &rty {
                        if params.len() != args.len() {
                            self.error(&loc, "type argument count mismatch");
                            Type::Error
                        } else {
                            Type::Struct(*mid, *sid, self.translate_types(args))
                        }
                    } else {
                        self.error(&loc, "type cannot have type arguments");
                        Type::Error
                    }
                } else {
                    rty
                }
            }
            Ref(is_mut, ty) => Type::Reference(*is_mut, Box::new(self.translate_type(&*ty))),
            Fun(args, result) => Type::Fun(
                self.translate_types(&args),
                Box::new(self.translate_type(&*result)),
            ),
            Unit => Type::Tuple(vec![]),
            Multiple(vst) => Type::Tuple(self.translate_types(vst)),
            UnresolvedError => Type::Error,
        }
    }
/// Translates a source AST type into a target AST type.
Translates a source AST type into a target AST type.
Translates a source AST type into a target AST type .
fn translate_type(&mut self, ty: &EA::Type) -> Type {
        use EA::Type_::*;
        match &ty.value {
            Apply(access, args) => {
                if let EA::ModuleAccess_::Name(n) = &access.value {
                    let check_zero_args = |et: &mut Self, ty: Type| {
                        if args.is_empty() {
                            ty
                        } else {
                            et.error(&et.to_loc(&n.loc), "expected no type arguments");
                            Type::Error
                        }
                    };
                    // Attempt to resolve as builtin type.
                    match n.value.as_str() {
                        "bool" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Bool));
                        }
                        "u8" => return check_zero_args(self, Type::new_prim(PrimitiveType::U8)),
                        "u64" => return check_zero_args(self, Type::new_prim(PrimitiveType::U64)),
                        "u128" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::U128));
                        }
                        "num" => return check_zero_args(self, Type::new_prim(PrimitiveType::Num)),
                        "range" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Range));
                        }
                        "address" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Address));
                        }
                        "signer" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::Signer));
                        }
                        "type" => {
                            return check_zero_args(self, Type::new_prim(PrimitiveType::TypeValue));
                        }
                        "vector" => {
                            if args.len() != 1 {
                                self.error(
                                    &self.to_loc(&ty.loc),
                                    "expected one type argument for `vector`",
                                );
                                return Type::Error;
                            } else {
                                return Type::Vector(Box::new(self.translate_type(&args[0])));
                            }
                        }
                        _ => {}
                    }
                    // Attempt to resolve as a type parameter.
                    let sym = self.symbol_pool().make(n.value.as_str());
                    if let Some(ty) = self.type_params_table.get(&sym).cloned() {
                        return check_zero_args(self, ty);
                    }
                    // Attempt to resolve as a type value.
                    if let Some(entry) = self.lookup_local(sym, false) {
                        let ty = entry.type_.clone();
                        self.check_type(
                            &self.to_loc(&n.loc),
                            &ty,
                            &Type::new_prim(PrimitiveType::TypeValue),
                            "in type",
                        );
                        return check_zero_args(self, Type::TypeLocal(sym));
                    }
                }
                let loc = self.to_loc(&access.loc);
                let sym = self.parent.module_access_to_qualified(access);
                let rty = self.parent.parent.lookup_type(&loc, &sym);
                if !args.is_empty() {
                    // Replace type instantiation.
                    if let Type::Struct(mid, sid, params) = &rty {
                        if params.len() != args.len() {
                            self.error(&loc, "type argument count mismatch");
                            Type::Error
                        } else {
                            Type::Struct(*mid, *sid, self.translate_types(args))
                        }
                    } else {
                        self.error(&loc, "type cannot have type arguments");
                        Type::Error
                    }
                } else {
                    rty
                }
            }
            Ref(is_mut, ty) => Type::Reference(*is_mut, Box::new(self.translate_type(&*ty))),
            Fun(args, result) => Type::Fun(
                self.translate_types(&args),
                Box::new(self.translate_type(&*result)),
            ),
            Unit => Type::Tuple(vec![]),
            Multiple(vst) => Type::Tuple(self.translate_types(vst)),
            UnresolvedError => Type::Error,
        }
    }
fn translate_type ( & mut self , ty : & EA :: Type ) -> Type { use EA :: Type_ :: * ; match & ty . value { Apply ( access , args ) => { if let EA :: ModuleAccess_ :: Name ( n ) = & access . value { let check_zero_args = | et : & mut Self , ty : Type | { if args . is_empty ( ) { ty } else { et . error ( & et . to_loc ( & n . loc ) , " " ) ; Type :: Error } } ; // Attempt to resolve as builtin type. match n . value . as_str ( ) { " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: Bool ) ) ; } " " => return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: U8 ) ) , " " => return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: U64 ) ) , " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: U128 ) ) ; } " " => return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: Num ) ) , " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: Range ) ) ; } " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: Address ) ) ; } " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: Signer ) ) ; } " " => { return check_zero_args ( self , Type :: new_prim ( PrimitiveType :: TypeValue ) ) ; } " " => { if args . len ( ) != 1 { self . error ( & self . to_loc ( & ty . loc ) , " " , ) ; return Type :: Error ; } else { return Type :: Vector ( Box :: new ( self . translate_type ( & args [ 0 ] ) ) ) ; } } _ => { } } // Attempt to resolve as a type parameter. let sym = self . symbol_pool ( ) . make ( n . value . as_str ( ) ) ; if let Some ( ty ) = self . type_params_table . get ( & sym ) . cloned ( ) { return check_zero_args ( self , ty ) ; } // Attempt to resolve as a type value. if let Some ( entry ) = self . lookup_local ( sym , false ) { let ty = entry . type_ . clone ( ) ; self . check_type ( & self . to_loc ( & n . loc ) , & ty , & Type :: new_prim ( PrimitiveType :: TypeValue ) , " " , ) ; return check_zero_args ( self , Type :: TypeLocal ( sym ) ) ; } } let loc = self . to_loc ( & access . loc ) ; let sym = self . parent . module_access_to_qualified ( access ) ; let rty = self . parent . parent . lookup_type ( & loc , & sym ) ; if ! args . is_empty ( ) { // Replace type instantiation. if let Type :: Struct ( mid , sid , params ) = & rty { if params . len ( ) != args . len ( ) { self . error ( & loc , " " ) ; Type :: Error } else { Type :: Struct ( * mid , * sid , self . translate_types ( args ) ) } } else { self . error ( & loc , " " ) ; Type :: Error } } else { rty } } Ref ( is_mut , ty ) => Type :: Reference ( * is_mut , Box :: new ( self . translate_type ( & * ty ) ) ) , Fun ( args , result ) => Type :: Fun ( self . translate_types ( & args ) , Box :: new ( self . translate_type ( & * result ) ) , ) , Unit => Type :: Tuple ( vec ! [ ] ) , Multiple ( vst ) => Type :: Tuple ( self . translate_types ( vst ) ) , UnresolvedError => Type :: Error , } }
Translates a source AST type into a target AST type.
Translates a source AST type into a target AST type .
&mut self
ty
&EA::Type
&mut self
ty
&EA::Type