Skip to content

Commit

Permalink
Fix problem with Sequence.each.operator contains
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed May 18, 2024
1 parent e40fcd5 commit e48e453
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/deemon/objects/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ seq_size(DeeObject *__restrict self) {
return NULL;
}

PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL
seq_tpcontains(DeeObject *self, DeeObject *item) {
return DeeSeq_DefaultContainsWithForeachDefault(self, item);
}

PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL
seq_getitem(DeeObject *self, DeeObject *index) {
size_t i;
Expand Down Expand Up @@ -1965,7 +1970,7 @@ seq_setitem(DeeObject *self, DeeObject *index, DeeObject *value) {
PRIVATE struct type_seq generic_seq_seq = {
/* .tp_iter = */ &seq_iterself,
/* .tp_sizeob = */ &seq_size,
/* .tp_contains = */ NULL,
/* .tp_contains = */ &seq_tpcontains,
/* .tp_getitem = */ &seq_getitem,
/* .tp_delitem = */ &seq_delitem,
/* .tp_setitem = */ &seq_setitem,
Expand Down
3 changes: 2 additions & 1 deletion src/deemon/runtime/operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -15641,7 +15641,8 @@ DeeType_InheritContains(DeeTypeObject *__restrict self) {

base = DeeTypeMRO_Init(&mro, self);
while ((base = DeeTypeMRO_NextDirectBase(&mro, base)) != NULL) {
if (!DeeType_InheritContains(base))
if (!base->tp_seq || !base->tp_seq->tp_contains &&

Check warning on line 15644 in src/deemon/runtime/operator.c

View workflow job for this annotation

GitHub Actions / build

suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
!DeeType_InheritContains(base))
continue;
base_seq = base->tp_seq;
LOG_INHERIT(base, self, "operator contains");
Expand Down
30 changes: 30 additions & 0 deletions util/test/deemon-sequence-each-contains.dee
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/deemon
/* Copyright (c) 2018-2024 Griefer@Work *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any damages *
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not *
* claim that you wrote the original software. If you use this software *
* in a product, an acknowledgement (see the following) in the product *
* documentation is required: *
* Portions Copyright (c) 2018-2024 Griefer@Work *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* 3. This notice may not be removed or altered from any source distribution. *
*/

local SEQ = { "Foo", "bAr" };

assert "foo" !in SEQ;
assert "bar" !in SEQ;
assert "baz" !in SEQ;

assert "foo" in SEQ.each.lower();
assert "bar" in SEQ.each.lower();
assert "baz" !in SEQ.each.lower();

0 comments on commit e48e453

Please sign in to comment.