/red-system/tests/source/compiler/inference-test.r
R | 58 lines | 41 code | 17 blank | 0 comment | 0 complexity | d7a4aeb6b269f8b5f02d7eaeec9fd848 MD5 | raw file
1REBOL [ 2 Title: "Red/System type inference test script" 3 Author: "Nenad Rakocevic" 4 File: %inference-test.reds 5 Rights: "Copyright (C) 2011 Nenad Rakocevic. All rights reserved." 6 License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt" 7] 8 9change-dir %../ 10 11;=== Helper functions === 12--assert-compiles?: func [src [string!] /local exe][ 13 exe: --compile-this src 14 either exe [ 15 --run exe 16 --assert qt/output = "" 17 ][ 18 qt/compile-error src 19 ] 20 --clean 21] 22 23;=== end of helper functions === 24 25 26~~~start-file~~~ "inference-compile" 27 28 --test-- "simple inference 1" 29 --assert-compiles? "foo: func [/local a][a: 1]" 30 31 --test-- "simple inference 2" 32 --assert-compiles? {foo: func [/local a b][a: true b: #"A"]} 33 34 --test-- "simple inference 3" 35 --assert-compiles? {foo: func [/local a][a: either true ["A"]["B"]]} 36 37 --test-- "simple inference 4" 38 --assert-compiles? "foo: func [/local a][while [true][a: 1]]" 39 40 --test-- "simple inference 5" 41 --assert-compiles? { 42 foo: func [return: [integer!] /local a][a: 123] 43 bar: func [/local b][b: foo] 44 } 45 46~~~end-file~~~ 47 48 49~~~start-file~~~ "inference-err" 50 51 --test-- "inference error" 52 --compile-this "foo: func [/local a][a]" 53 --assert-msg? "*** Compilation Error: local variable a used before being initialized!" 54 --clean 55 56~~~end-file~~~ 57 58