From ed4dd017d351b9d7de8ee0630fd257a9896b944b Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Mon, 29 May 2017 22:23:11 +0200 Subject: [PATCH 3/3] Fix the type inference with foreign types We can't trust the returned values to be of the base type since we push it through the conversion procedures. Ideally we'd avoid adding explicit type annotations in this situation, and let the scrutinizer deal with it, but that's a lot trickier to do with the current code base. --- support.scm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/support.scm b/support.scm index 2c04d2e..366bae2 100644 --- a/support.scm +++ b/support.scm @@ -1241,7 +1241,14 @@ ;; Used only in chicken-ffi-syntax.scm; can we move it there? (define (foreign-type->scrutiny-type t mode) ; MODE = 'arg | 'result - (let ((ft (final-foreign-type t))) + ;; Take into account the fact we can't have a precise type if + ;; there are user-specified conversion procedures. It would be + ;; better if we could simply let the scrutinizer do its work on + ;; the procedure, instead. + (let* ((conv-slot (if (eq? mode 'arg) 1 2)) + (ft-vec (and (symbol? t) (lookup-foreign-type t))) + (ft (and (or (not ft-vec) (not (vector-ref ft-vec conv-slot))) + (final-foreign-type t)))) (case ft ((void) 'undefined) ((char unsigned-char) 'char) -- 2.1.4