[red-knot] Add debug assert to check for duplicate definitions (#13214)

## Summary

Closes: #13085

## Test Plan

`cargo insta test --workspace`
This commit is contained in:
Dhruv Manilawala 2024-09-04 11:23:32 +05:30 committed by GitHub
parent e1e9143c47
commit 862bd0c429
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -193,8 +193,11 @@ impl<'db> SemanticIndexBuilder<'db> {
countme::Count::default(), countme::Count::default(),
); );
self.definitions_by_node let existing_definition = self
.definitions_by_node
.insert(definition_node.key(), definition); .insert(definition_node.key(), definition);
debug_assert_eq!(existing_definition, None);
self.current_use_def_map_mut() self.current_use_def_map_mut()
.record_definition(symbol, definition); .record_definition(symbol, definition);
@ -327,10 +330,11 @@ impl<'db> SemanticIndexBuilder<'db> {
// Insert a mapping from the parameter to the same definition. // Insert a mapping from the parameter to the same definition.
// This ensures that calling `HasTy::ty` on the inner parameter returns // This ensures that calling `HasTy::ty` on the inner parameter returns
// a valid type (and doesn't panic) // 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(), DefinitionNodeRef::from(AnyParameterRef::Variadic(&with_default.parameter)).key(),
definition, definition,
); );
debug_assert_eq!(existing_definition, None);
} }
} }