Skip to content

Commit

Permalink
Set __hash__ to None when clearing it, to match CPython
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Jan 7, 2024
1 parent efca612 commit 114b66d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void krk_finalizeClass(KrkClass * _class) {
*entry->method = NULL;
KrkClass * _base = _class;
while (_base) {
if (krk_tableGet(&_base->methods, vm.specialMethodNames[entry->index], &tmp)) break;
if (krk_tableGet_fast(&_base->methods, AS_STRING(vm.specialMethodNames[entry->index]), &tmp)) break;
_base = _base->base;
}
if (_base && (IS_CLOSURE(tmp) || IS_NATIVE(tmp)) && (!(AS_OBJECT(tmp)->flags & KRK_OBJ_FLAGS_FUNCTION_IS_STATIC_METHOD) || entry->index == METHOD_NEW)) {
Expand All @@ -258,6 +258,10 @@ void krk_finalizeClass(KrkClass * _class) {
if (_class->base && _class->_eq != _class->base->_eq) {
if (_class->_hash == _class->base->_hash) {
_class->_hash = NULL;
KrkValue _unused;
if (!krk_tableGet_fast(&_class->methods, AS_STRING(vm.specialMethodNames[METHOD_HASH]), &_unused)) {
krk_tableSet(&_class->methods, OBJECT_VAL(vm.specialMethodNames[METHOD_HASH]), NONE_VAL());
}
}
}

Expand Down

0 comments on commit 114b66d

Please sign in to comment.