]> gitweb.factorcode.org Git - factor.git/commitdiff
generic: check valid combination/effect.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Aug 2015 22:13:23 +0000 (15:13 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Aug 2015 22:13:23 +0000 (15:13 -0700)
core/generic/generic.factor
core/generic/standard/standard-tests.factor
core/generic/standard/standard.factor

index 88ab8ef80eb0ef1bd0ea1155b5356d9f5a2c0f10..c861f7c54bc894dd9c3c90fd1711f5ceae24f75d 100644 (file)
@@ -2,8 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.algebra
 classes.algebra.private classes.maybe classes.private
-combinators definitions kernel make namespaces sequences sets
-words ;
+combinators definitions kernel make math namespaces sequences
+sets words ;
 IN: generic
 
 ! Method combination protocol
@@ -186,8 +186,12 @@ M: method forget*
         [ call-next-method ] bi
     ] if ;
 
+GENERIC# check-combination-effect 1 ( combination effect -- )
+
+M: object check-combination-effect 2drop ;
+
 : define-generic ( word combination effect -- )
-    [ nip swap set-stack-effect ]
+    [ [ check-combination-effect ] keep swap set-stack-effect ]
     [
         drop
         2dup [ "combination" word-prop ] dip = [ 2drop ] [
index edaa71eed67c0516bd77afda18e4b12a4b2f4b13..fdf1fd7b634cbf1d2a2c05d15c69d77263e81e0d 100644 (file)
@@ -365,14 +365,20 @@ M: c funky* "c" , call-next-method ;
 { f } [ "xyz" "generic.standard.tests" lookup-word pic-def>> ] unit-test
 { f } [ "xyz" "generic.standard.tests" lookup-word "decision-tree" word-prop ] unit-test
 
-! Corner case
+! Corner cases
+[ "IN: generic.standard.tests GENERIC: broken-generic ( -- )" eval( -- ) ]
+[ error>> bad-dispatch-position? ]
+must-fail-with
 [ "IN: generic.standard.tests GENERIC# broken-generic# -1 ( a -- b )" eval( -- ) ]
 [ error>> bad-dispatch-position? ]
 must-fail-with
+[ "IN: generic.standard.tests GENERIC# broken-generic# 1 ( a -- b )" eval( -- ) ]
+[ error>> bad-dispatch-position? ]
+must-fail-with
 
 ! Generic words cannot be inlined
-{ } [ "IN: generic.standard.tests GENERIC: foo ( -- x )" eval( -- ) ] unit-test
-[ "IN: generic.standard.tests GENERIC: foo ( -- x ) inline" eval( -- ) ] must-fail
+{ } [ "IN: generic.standard.tests GENERIC: foo ( -- x )" eval( -- ) ] unit-test
+[ "IN: generic.standard.tests GENERIC: foo ( -- x ) inline" eval( -- ) ] must-fail
 
 ! Moving a method from one vocab to another didn't always work
 GENERIC: move-method-generic ( a -- b )
index e8b342e777703ac032217cb8b0b3f28ec877b2e2..c214e2f9990c4e2d5fe3aabc180496ffff69eec6 100644 (file)
@@ -13,6 +13,10 @@ TUPLE: standard-combination < single-combination # ;
     dup 0 < [ bad-dispatch-position ] when
     standard-combination boa ;
 
+M: standard-combination check-combination-effect
+    [ dispatch# ] [ in>> length ] bi* over >
+    [ drop ] [ bad-dispatch-position ] if ;
+
 PREDICATE: standard-generic < generic
     "combination" word-prop standard-combination? ;