hashtables: fix the error thrown by H{ 1 }.

locals-and-roots
Doug Coleman 2016-06-23 23:52:55 -07:00
parent 0c22382c98
commit 52a9dfb11a
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,5 @@
USING: accessors assocs continuations fry hashtables kernel make
math namespaces sequences tools.test ;
math namespaces sequences tools.test eval ;
{ H{ } } [ { } [ dup ] H{ } map>assoc ] unit-test
@ -125,6 +125,9 @@ H{ } "x" set
! non-integer capacity not allowed
[ 0.75 <hashtable> ] must-fail
[ "H{ 1 }" eval( str -- obj ) ] must-fail
[ "H{ 1 2 -- 3 }" eval( str -- obj ) ] must-fail
! Another crash discovered by erg
{ } [
H{ } clone

View File

@ -194,7 +194,13 @@ M: hashtable assoc-like
ERROR: malformed-hashtable-pair seq pair ;
: check-hashtable ( seq -- seq )
dup [ dup length 2 = [ drop ] [ malformed-hashtable-pair ] if ] each ;
dup [
dup sequence? [
dup length 2 = [ drop ] [ malformed-hashtable-pair ] if
] [
malformed-hashtable-pair
] if
] each ;
: parse-hashtable ( seq -- hashtable )
check-hashtable H{ } assoc-clone-like ;