Currently, the ModuleBuilder::declare_function method updates the existing function declaration when a function with the same name is declared again. This behavior can unintentionally overwrite previous declarations, potentially leading to inconsistencies or unexpected behaviors in the module.
We propose changing this behavior so that declare_function returns a Result. If a function with the same name is already registered and its signature differs from the new declaration, the method should return an error instead of updating the existing declaration.
Proposed Changes:
-
Add BuilderError type
-
Modify Return Type:
- Change the return type of
ModuleBuilder::declare_function to return a Result<Function, BuilderError>
-
Conflict Detection:
- Implement a check to determine if a function with the same name already exists.
- If it exists and the signature matches, return the existing function.
- If it exists and the signature differs, return an error indicating a conflicting declaration.
Currently, the
ModuleBuilder::declare_functionmethod updates the existing function declaration when a function with the same name is declared again. This behavior can unintentionally overwrite previous declarations, potentially leading to inconsistencies or unexpected behaviors in the module.We propose changing this behavior so that
declare_functionreturns aResult. If a function with the same name is already registered and its signature differs from the new declaration, the method should return an error instead of updating the existing declaration.Proposed Changes:
Add
BuilderErrortypeModify Return Type:
ModuleBuilder::declare_functionto return aResult<Function, BuilderError>Conflict Detection: