On Thu, Jul 11, 2019 at 03:15:00PM +0300, megane wrote:
> Of course if this is dropped the other conditions must still meet.
> 
> Here's your proposed condition:
> 
>   (and (not captured)
>        (or (and (not (db-get db name 'unknown))
>                 (db-get db name 'value))
>            (and (not assigned)
>                 (not (db-get db name 'assigned))
>                 (or (not (variable-visible?
>                           name block-compilation))
>                     (not (db-get db name 'global))) )
>               ))
> 
> 
> If the (not captured) part is just dropped then if the first branch of
> the or is taken, namely this:
> 
>   (and (not (db-get db name 'unknown))
>        (db-get db name 'value))
> 
> then it's not checked that the variable to be replaced is never assigned
> to! Here's a case that triggers the error:
> 
>   (define (foo x)
>     (letrec ((pe* (lambda () (print x) (pe*))))
>       (pe*)))
>   (foo '((foo1 e)))
>   (foo 'foo2)
> 
> The letrec expands to an assignment and to a (##core#undefined) that
> triggers the first branch of the or.
> 
> Here's a correct way to drop the (not captured) check:
> 
>   (and (not assigned)
>        (or (and (not (db-get db name 'unknown))
>                 (db-get db name 'value))
>            (and (not (db-get db name 'assigned))
>                 (or (not (variable-visible?
>                           name block-compilation))
>                     (not (db-get db name 'global))) ) ))

Wow, nice catch!  That makes a lot of sense.  I'll cook up a proper
patch unless someone beats me to it.

Cheers,
Peter

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to