@@ -618,8 +618,35 @@ impl Scope {
618618 /// There are any undefined aliases.
619619 pub fn insert_alias ( & mut self , name : AliasName , ty : AliasedType ) -> Result < ( ) , Error > {
620620 let resolved_ty = self . resolve ( & ty) ?;
621- self . aliases . insert ( name, resolved_ty) ;
622- Ok ( ( ) )
621+
622+ match self . aliases . entry ( name. clone ( ) ) {
623+ Entry :: Occupied ( _) => Err ( Error :: RedefinedAlias ( name) ) ,
624+ Entry :: Vacant ( entry) => {
625+ entry. insert ( resolved_ty) ;
626+ Ok ( ( ) )
627+ }
628+ }
629+ // self.aliases.insert(name, resolved_ty);
630+ // Ok(())
631+ }
632+
633+ /// Insert a custom function into the global map.
634+ ///
635+ /// ## Errors
636+ ///
637+ /// The function has already been defined.
638+ pub fn insert_function (
639+ & mut self ,
640+ name : FunctionName ,
641+ function : CustomFunction ,
642+ ) -> Result < ( ) , Error > {
643+ match self . functions . entry ( name. clone ( ) ) {
644+ Entry :: Occupied ( _) => Err ( Error :: FunctionRedefined ( name) ) ,
645+ Entry :: Vacant ( entry) => {
646+ entry. insert ( function) ;
647+ Ok ( ( ) )
648+ }
649+ }
623650 }
624651
625652 /// Insert a parameter into the global map.
@@ -671,25 +698,6 @@ impl Scope {
671698 )
672699 }
673700
674- /// Insert a custom function into the global map.
675- ///
676- /// ## Errors
677- ///
678- /// The function has already been defined.
679- pub fn insert_function (
680- & mut self ,
681- name : FunctionName ,
682- function : CustomFunction ,
683- ) -> Result < ( ) , Error > {
684- match self . functions . entry ( name. clone ( ) ) {
685- Entry :: Occupied ( _) => Err ( Error :: FunctionRedefined ( name) ) ,
686- Entry :: Vacant ( entry) => {
687- entry. insert ( function) ;
688- Ok ( ( ) )
689- }
690- }
691- }
692-
693701 /// Get the definition of a custom function.
694702 pub fn get_function ( & self , name : & FunctionName ) -> Option < & CustomFunction > {
695703 self . functions . get ( name)
0 commit comments