Skip to content

Commit

Permalink
[red-knot] Add debug assert to check for duplicate definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Sep 3, 2024
1 parent 3739d27 commit 84b577e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/red_knot_python_semantic/src/semantic_index/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,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);

Expand Down Expand Up @@ -324,10 +327,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);
}
}

Expand Down

0 comments on commit 84b577e

Please sign in to comment.