Hi,
back at playing with types - my current impression is that the compiler
is a little too optimistic (goal: get as much warnings as
possible - optimizations are no concern here).
Example A - compiler gives warning - I am happy:
(: my-add (fixnum fixnum --> float)) ; note the float return type
(define my-add (lambda (a b)
(+ a b)))
(: some-val-w-1 fixnum)
(define some-val-w-1 (my-add 0 1)) ; warning
Example B - compiler gives no warning (not sure why not - I would have
hoped that the compiler assumes the "worst case" - meaning "my-add-2"
returns a float and therefore the variable "some-val-nw-2" cannot be a
fixnum)
(define-type mixed-type (or fixnum float))
(: my-add-2 (fixnum mixed-type --> mixed-type))
(define my-add-2 (lambda (a b)
(+ a b)))
(: some-val-nw-2 fixnum)
(define some-val-nw-2 (my-add-2 1 0.3)) ; return value will be a float
Am I missing some compiler-flags that I am supposed to use?
Chicken 4 (4.13) and Chicken 5 are behaving in the same way - I am
using no compiler-flags - just "csc <filename>" - by the way: using the
compiler-flag "-optimize-level 0" makes the first warning disappear.
Attached is the (Chicken 5) source-code of the tests - "-w-" in a name
means "warning", "-nw-" in a name means "no warning" (and my goal was
to get a warning in all cases - so "-w-" means I got what I expected).
lg
Martin
(module type-lost-simple ()
(import
scheme
chicken.base
chicken.type)
(: my-add (fixnum fixnum --> float))
(define my-add (lambda (a b)
(+ a b)))
(define-type mixed-type (or fixnum float))
(: my-add-2 (fixnum mixed-type --> mixed-type))
(define my-add-2 (lambda (a b)
(+ a b)))
(: some-val-nw-1 fixnum)
(define some-val-nw-1 (+ 1 0.3))
(: some-val-nw-2 fixnum)
(define some-val-nw-2 (my-add-2 1 0.3))
(: some-val-w-1 fixnum)
(define some-val-w-1 (my-add 0 1)))_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users