Skip to content

Commit 862bd0c

Browse files
authored
[red-knot] Add debug assert to check for duplicate definitions (#13214)
## Summary Closes: #13085 ## Test Plan `cargo insta test --workspace`
1 parent e1e9143 commit 862bd0c

File tree

1 file changed

+6
-2
lines changed
  • crates/red_knot_python_semantic/src/semantic_index

1 file changed

+6
-2
lines changed

crates/red_knot_python_semantic/src/semantic_index/builder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ impl<'db> SemanticIndexBuilder<'db> {
193193
countme::Count::default(),
194194
);
195195

196-
self.definitions_by_node
196+
let existing_definition = self
197+
.definitions_by_node
197198
.insert(definition_node.key(), definition);
199+
debug_assert_eq!(existing_definition, None);
200+
198201
self.current_use_def_map_mut()
199202
.record_definition(symbol, definition);
200203

@@ -327,10 +330,11 @@ impl<'db> SemanticIndexBuilder<'db> {
327330
// Insert a mapping from the parameter to the same definition.
328331
// This ensures that calling `HasTy::ty` on the inner parameter returns
329332
// a valid type (and doesn't panic)
330-
self.definitions_by_node.insert(
333+
let existing_definition = self.definitions_by_node.insert(
331334
DefinitionNodeRef::from(AnyParameterRef::Variadic(&with_default.parameter)).key(),
332335
definition,
333336
);
337+
debug_assert_eq!(existing_definition, None);
334338
}
335339
}
336340

0 commit comments

Comments
 (0)