From 862bd0c429f002cf65f931fec2ad2f02fa41837d Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 4 Sep 2024 11:23:32 +0530 Subject: [PATCH] [red-knot] Add debug assert to check for duplicate definitions (#13214) ## Summary Closes: #13085 ## Test Plan `cargo insta test --workspace` --- .../src/semantic_index/builder.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/red_knot_python_semantic/src/semantic_index/builder.rs b/crates/red_knot_python_semantic/src/semantic_index/builder.rs index 38637abeb21f7..c76990f3f4261 100644 --- a/crates/red_knot_python_semantic/src/semantic_index/builder.rs +++ b/crates/red_knot_python_semantic/src/semantic_index/builder.rs @@ -193,8 +193,11 @@ impl<'db> SemanticIndexBuilder<'db> { countme::Count::default(), ); - self.definitions_by_node + let existing_definition = self + .definitions_by_node .insert(definition_node.key(), definition); + debug_assert_eq!(existing_definition, None); + self.current_use_def_map_mut() .record_definition(symbol, definition); @@ -327,10 +330,11 @@ impl<'db> SemanticIndexBuilder<'db> { // Insert a mapping from the parameter to the same definition. // This ensures that calling `HasTy::ty` on the inner parameter returns // a valid type (and doesn't panic) - self.definitions_by_node.insert( + let existing_definition = self.definitions_by_node.insert( DefinitionNodeRef::from(AnyParameterRef::Variadic(&with_default.parameter)).key(), definition, ); + debug_assert_eq!(existing_definition, None); } }