bugKawa - Bugs: bug #40616, Unhygienic syntax-rules

 
 

bug #40616: Unhygienic syntax-rules

Submitter:  John Tobey <jtobey>
Submitted:  Mon 18 Nov 2013 01:29:31 AM UTC
   
 
Category:  Scheme library Severity:  3 - Normal
Item Group:  Unexpected result Status:  Fixed
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 19 Nov 2013 12:47:10 AM UTC, comment #3: 

That's a different problem.  Again, I was afraid this might require major changes, but it turned out to be a clean and simple fix.

Thanks for the testcase.  It and the fix are checked in.

Per Bothner <bothner>
Group administrator
Mon 18 Nov 2013 11:37:49 PM UTC, comment #2: 

Thanks for the speedy fix.  Still, this gives me a duplicate declaration error where I would expect it to succeed:


(define-syntax def-a
  (syntax-rules ()
    ((_) (define a #f))))
(def-a)
(def-a)


John Tobey <jtobey>
Mon 18 Nov 2013 09:18:55 PM UTC, comment #1: 

At first glance, I was afraid this would require major changes to fix.  However, it looks like a fairly modest and "local" bug in a single function.

When we create a definition in a macro, the "scope" (ScopeExp) object used is somewhat schizophrenic: the "real" scope used for optimization and code generation vs the "name lookup" scope used during macro expansion and name resolution.  The latter is a special temporary TemplateScope created when expanding a syntax template.  We need to set up some special monkeying around in that we create a special "alias declaration", so we can adjust it for the real scopes for later compilation stages.

The logic for this worked when passing in an explicit TemplateScope (via the nameSyntax parameter), but not when doing so implicitly - i.e. we had previously set the current scope to a TemplateScope.

The fix is checked in, along with your testcase.  Thanks for the clean testcase, and I'm embarrassed a simple bug like that lasted so long.

Per Bothner <bothner>
Group administrator
Mon 18 Nov 2013 01:29:31 AM UTC, original submission:  

This program outputs "correct" in Racket, Guile, and RnRS [1] but "wrong" in Kawa.


(define-syntax def-a
  (syntax-rules ()
    ((_) (define a 'wrong))))

(display (let ((a 'correct)) (def-a) a))
(newline)


[1] e.g., R6RS Section 9.2: "If a macro transformer inserts a binding for an identifier (variable or keyword) not appearing in the macro use, the identifier is in effect renamed throughout its scope to avoid conflicts with other identifiers."

John Tobey <jtobey>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by jtobey (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-11-18 bothner Assigned toNone bothner
        Open/ClosedOpen Closed
    2013-11-18 bothner StatusNone Fixed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code