Hi all, Here's a patch that fixes #884. The problem was that when modules declarations are canonicalized, all subexpressions are canonicalized in the dynamic extent of a with-property-restore.
The define-type call expands to a call to ##sys#put/restore!, which sets a property on the user-defined type's symbol which will be restored as soon as with-property-restore returns. Originally, ##core#the calls would simply be kept (but stripped of all syntax), which means the final form would be (##core#the footype #t '"bar"). This form survives the call to with-property-restore and thus the canonicalization process. (you can see this when you run "csc -scrutinize -debug 2 test.scm") The scrutinizer gets invoked much later when the complete source has been canonicalized, but at this time it doesn't know about this footype anymore and you get the error. The reason it works when the custom type is defined outside a module is because there is no with-property-restore call involved in canonicalization of the toplevel forms. The fix is simple; make the canonicalization process canonicalize type names to core names by looking up the custom name and converting it to a "core" typename while still inside the dynamic extent of the with-property-restore call in canonicalize-expression. Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth
>From 67e4305b1f6011e2991ab4b5512ce158ae824e02 Mon Sep 17 00:00:00 2001 From: Peter Bex <[email protected]> Date: Sat, 7 Jul 2012 11:40:23 +0200 Subject: [PATCH] Resolve user-defined scrutiny types at canonicalization time, before with-property-restore in each module's expansion is compiled away and ##compiler#type-abbreviation properties are restored. Fixes #884. --- compiler.scm | 2 +- tests/scrutiny-tests.scm | 8 ++++++++ tests/scrutiny.expected | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler.scm b/compiler.scm index 94d178d..68061e0 100644 --- a/compiler.scm +++ b/compiler.scm @@ -538,7 +538,7 @@ ((##core#the) `(##core#the - ,(##sys#strip-syntax (cadr x)) + ,(validate-type (##sys#strip-syntax (cadr x)) #f) ,(caddr x) ,(walk (cadddr x) e se dest ldest h ln))) diff --git a/tests/scrutiny-tests.scm b/tests/scrutiny-tests.scm index 5f0f56a..abe01f7 100644 --- a/tests/scrutiny-tests.scm +++ b/tests/scrutiny-tests.scm @@ -134,3 +134,11 @@ (import chicken scheme) (define (blabla) (+ 1 'x))) + +;; Reported by megane in #884: +;; +;; Custom types defined in modules need to be resolved during canonicalization +(module bar () + (import chicken scheme) + (define-type footype string) + (the footype "bar")) \ No newline at end of file diff --git a/tests/scrutiny.expected b/tests/scrutiny.expected index 609757c..a79e854 100644 --- a/tests/scrutiny.expected +++ b/tests/scrutiny.expected @@ -37,7 +37,7 @@ Warning: at toplevel: (scrutiny-tests.scm:28) in procedure call to `+', expected argument #2 of type `number', but was given an argument of type `symbol' Warning: at toplevel: - assignment of value of type `fixnum' to toplevel variable `car' does not match declared type `(forall (a132) (procedure car ((pair a132 *)) a132))' + assignment of value of type `fixnum' to toplevel variable `car' does not match declared type `(forall (a140) (procedure car ((pair a140 *)) a140))' Warning: at toplevel: expected in `let' binding of `g8' a single result, but were given 2 results -- 1.7.9.1
_______________________________________________ Chicken-hackers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-hackers
