Skip to content

Commit

Permalink
Make creating dictionary with mutable key fail
Browse files Browse the repository at this point in the history
An immediate dictionary defined with a mutable key was skipping the
invalid element of the dictionary, but going ahead and returning a
dictionary with the remaining valid elements. Make that an error
instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed May 18, 2020
1 parent 0dd0797 commit 0d9875b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion snek-list.c
Expand Up @@ -280,7 +280,7 @@ snek_list_imm(snek_offset_t size, snek_list_type_t type)
s -= 2;
snek_poly_t key = snek_stack_pick(s+1);
snek_poly_t value = snek_stack_pick(s);
snek_poly_t *ref = _snek_list_ref(list, key, false, true);
snek_poly_t *ref = _snek_list_ref(list, key, true, true);
if (ref)
*ref = value;
}
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Expand Up @@ -72,6 +72,7 @@ FAIL_TESTS = \
fail-interpolate-missing.py \
fail-interpolate-extra.py \
fail-interpolate-badformat.py \
fail-dictionary-mutable.py \
$(SYNTAX_TESTS)

check:
Expand Down
14 changes: 14 additions & 0 deletions test/fail-dictionary-mutable.py
@@ -0,0 +1,14 @@
#
# Copyright © 2020 Keith Packard <keithp@keithp.com>
#
# 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 Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
a = {{"hello": "world"}: "foo"}

0 comments on commit 0d9875b

Please sign in to comment.