# HG changeset patch # User Paul Boddie # Date 1716303730 -7200 # Node ID e6010ccae0c0521094eb1803921305ceec028b6d # Parent c8149a01d932334c3b51467324f00f901f536d9b Fixed list element assignment, overlooked in previous value replacement changes. diff -r c8149a01d932 -r e6010ccae0c0 templates/native/list.c --- a/templates/native/list.c Tue May 21 16:59:25 2024 +0200 +++ b/templates/native/list.c Tue May 21 17:02:10 2024 +0200 @@ -1,6 +1,6 @@ /* Native functions for list operations. -Copyright (C) 2016, 2017, 2021, 2023 Paul Boddie +Copyright (C) 2016, 2017, 2021, 2023, 2024 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -120,7 +120,7 @@ __int i = __TOINT(index); /* Set the element. */ - elements[i] = value; + __set_attr(&elements[i], value); return __builtins___none_None; } diff -r c8149a01d932 -r e6010ccae0c0 tests/list.py --- a/tests/list.py Tue May 21 16:59:25 2024 +0200 +++ b/tests/list.py Tue May 21 17:02:10 2024 +0200 @@ -102,3 +102,6 @@ e[0] += e[1] print e # [3, 1, 3] + +e[0] += e[1] + e[2] +print e # [7, 1, 3] diff -r c8149a01d932 -r e6010ccae0c0 tests/values.py --- a/tests/values.py Tue May 21 16:59:25 2024 +0200 +++ b/tests/values.py Tue May 21 17:02:10 2024 +0200 @@ -2,6 +2,28 @@ a = a - 1.0 return a +def test_assign(l, x): + l[0] = x + +def test_augmented(l, x): + l[0] += x + l[1] + x = 2.0 print test(x) # 1.0 print x # 2.0 + +l = [1, 2, 3] +test_assign(l, 4) +print l # [4, 2, 3] + +l2 = [1, 2, 3] +test_augmented(l2, 1) +print l2 # [4, 2, 3] + +l3 = [1.0, 2.0, 3.0] +test_assign(l3, 4.0) +print l3 # [4.0, 2.0, 3.0] + +l4 = [1.0, 2.0, 3.0] +test_augmented(l4, 1.0) +print l4 # [4.0, 2.0, 3.0]