1 USING: tools.test eval compiler compiler.errors compiler.units definitions kernel math
2 namespaces macros assocs ;
3 IN: compiler.tests.redefine0
5 ! Test ripple-up behavior
7 : test-2 ( -- ) test-1 ;
9 [ test-2 ] [ not-compiled? ] must-fail-with
11 { } [ "IN: compiler.tests.redefine0 : test-1 ( -- ) ;" eval( -- ) ] unit-test
13 { 0 0 } [ test-1 ] must-infer-as
15 { } [ test-2 ] unit-test
21 ] with-compilation-unit
24 : test-3 ( a -- ) drop ;
25 : test-4 ( -- ) [ 1 2 3 ] test-3 ;
27 { } [ test-4 ] unit-test
29 { } [ "IN: compiler.tests.redefine0 USE: kernel : test-3 ( a -- ) call ; inline" eval( -- ) ] unit-test
31 [ test-4 ] [ not-compiled? ] must-fail-with
37 ] with-compilation-unit
40 : test-5 ( a -- quot ) ;
41 : test-6 ( a -- b ) test-5 ;
43 { 31337 } [ 31337 test-6 ] unit-test
45 { } [ "IN: compiler.tests.redefine0 USING: macros kernel ; MACRO: test-5 ( a -- quot ) drop [ ] ;" eval( -- ) ] unit-test
47 [ 31337 test-6 ] [ not-compiled? ] must-fail-with
53 ] with-compilation-unit
56 GENERIC: test-7 ( a -- b )
60 : test-8 ( a -- b ) 255 bitand test-7 ;
62 [ 1 test-7 ] [ not-compiled? ] must-fail-with
63 [ 1 test-8 ] [ not-compiled? ] must-fail-with
65 { } [ "IN: compiler.tests.redefine0 USING: macros math kernel ; GENERIC: test-7 ( x y -- z ) : test-8 ( a b -- c ) 255 bitand test-7 ;" eval( -- ) ] unit-test
67 { 4 } [ 1 3 test-7 ] unit-test
68 { 4 } [ 1 259 test-8 ] unit-test
74 ] with-compilation-unit
77 ! Indirect dependency on an unoptimized word
80 [ test-9 ] quot set-global
81 MACRO: test-10 ( -- quot ) quot get ; >>
82 : test-11 ( -- ) test-10 ;
84 { } [ test-11 ] unit-test
86 { } [ "IN: compiler.tests.redefine0 : test-9 ( -- ) 1 ;" eval( -- ) ] unit-test
88 ! test-11 should get recompiled now
90 [ test-11 ] [ not-compiled? ] must-fail-with
92 { } [ "IN: compiler.tests.redefine0 : test-9 ( -- a ) 1 ;" eval( -- ) ] unit-test
94 { } [ "IN: compiler.tests.redefine0 : test-9 ( -- ) ;" eval( -- ) ] unit-test
96 { } [ test-11 ] unit-test
106 ] with-compilation-unit