Skip to content
Snippets Groups Projects
Commit 97bb9ab3 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Detect conflicting module names in `construct_runtime!` (#7968)

parent 2fcff6a1
No related merge requests found
......@@ -62,6 +62,7 @@ impl Module {
fn complete_modules(decl: impl Iterator<Item = ModuleDeclaration>) -> syn::Result<Vec<Module>> {
let mut indices = HashMap::new();
let mut last_index: Option<u8> = None;
let mut names = HashMap::new();
decl
.map(|module| {
......@@ -88,6 +89,14 @@ fn complete_modules(decl: impl Iterator<Item = ModuleDeclaration>) -> syn::Resul
return Err(err);
}
if let Some(used_module) = names.insert(module.name.clone(), module.name.span()) {
let msg = "Two modules with the same name!";
let mut err = syn::Error::new(used_module, &msg);
err.combine(syn::Error::new(module.name.span(), &msg));
return Err(err);
}
Ok(Module {
name: module.name,
index: final_index,
......
use frame_support::construct_runtime;
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
Balance: balances::{Module},
Balance: balances::{Module},
}
}
fn main() {}
error: Two modules with the same name!
--> $DIR/conflicting_module_name.rs:10:3
|
10 | Balance: balances::{Module},
| ^^^^^^^
error: Two modules with the same name!
--> $DIR/conflicting_module_name.rs:11:3
|
11 | Balance: balances::{Module},
| ^^^^^^^
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment