with-syntax should give more informative error

Bug #206844 reported by Derick Eddington
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
High
Abdulaziz Ghuloum

Bug Description

Should tell it came from a failed with-syntax matching at least.

Ikarus Scheme version 0.0.3+ (revision 1430, build 2008-03-25)
Copyright (c) 2006-2008 Abdulaziz Ghuloum

> (with-syntax ([a #'()])
    (with-syntax ([(b) #'a]) #'b))
Unhandled exception
 Condition components:
   1. &message: "invalid syntax"
   2. &syntax:
       form: (())
       subform: #f
>

Related branches

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Will fix. Thanks. Do you have any suggestions for what the error should look like?

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Derick Eddington (derick-eddington) wrote : Re: [Bug 206844] with-syntax should give more informative error

On Wed, 2008-03-26 at 01:41 +0000, Abdulaziz Ghuloum wrote:
> Do you have any suggestions for what the error
> should look like?

I suggest there be a &who of 'with-syntax, the &message be "failed to
match", and the form field of the &syntax be the entire with-syntax form
and the subform field be the with-syntax binding clause that failed.

> (with-syntax ([a #'()])
    (with-syntax ([(b) #'a]) #'b))
Unhandled exception
 Condition components:
   1. &who: with-syntax
   2. &message: "failed to match"
   3. &syntax:
       form: (with-syntax (((b) #'a)) #'b)
       subform: ((b) #'a)
>

Revision history for this message
Derick Eddington (derick-eddington) wrote :

On Sun, 2008-03-30 at 22:10 -0700, Derick Eddington wrote:
> and the subform field be the with-syntax binding clause that failed.

On second thought, I suggest the subform field be just the pattern, so
it doesn't include the expression which would already be shown in the
form field.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

On Mar 31, 2008, at 1:06 AM, Derick Eddington wrote:

> I suggest there be a &who of 'with-syntax, the &message be "failed to
> match", and the form field of the &syntax be the entire with-syntax
> form
> and the subform field be the with-syntax binding clause that failed.
>
>> (with-syntax ([a #'()])
> (with-syntax ([(b) #'a]) #'b))
> Unhandled exception
> Condition components:
> 1. &who: with-syntax
> 2. &message: "failed to match"
> 3. &syntax:
> form: (with-syntax (((b) #'a)) #'b)
> subform: ((b) #'a

That doesn't work. That says that there is a problem with the syntax
of the (with-syntax --- ---) form itself, like when you try (with-
syntax 12 13). What's happening here is not a problem with the with-
syntax; it's a problem with the data that you're passing it. I'm
inclined to make it raise an assertion like:

Unhandled exception
  Condition components:
    1. &assertion
    2. &who: with-syntax
    3. &message: "failed to match"
    4. &irritants: (#<syntax ()>)

but it irritates me for some reason.

Revision history for this message
Derick Eddington (derick-eddington) wrote :

On Mon, Mar 31, 2008 at 2:29 AM, Abdulaziz Ghuloum
<email address hidden> wrote:
> That doesn't work. That says that there is a problem with the syntax
> of the (with-syntax --- ---) form itself, like when you try (with-
> syntax 12 13). What's happening here is not a problem with the with-
> syntax; it's a problem with the data that you're passing it.

Yeah, that makes sense.

> I'm
> inclined to make it raise an assertion like:
>
> Unhandled exception
> Condition components:
> 1. &assertion
> 2. &who: with-syntax
> 3. &message: "failed to match"
> 4. &irritants: (#<syntax ()>)
>
> but it irritates me for some reason.

I'm fine with that (ideally with &irritants having the failed pattern
to show). Why don't you like it? I've also made a macro which uses
assertion-violation because of an expand-time error that's not a
syntax error. I wonder if an additional condition like &phase would
be cool so you'd know when expand-time non-syntax errors are
happening, though I have little idea how much value this will actually
have.

--Derick

Revision history for this message
Derick Eddington (derick-eddington) wrote :

I don't think you have to use &irritants with &assertion; you could
instead use a private condition type &pattern which shows the pattern
syntax -- would a syntax object with source location info or a
non-syntax object s-expr of the pattern syntax be best...? I'm leaning
towards syntax object with location info because of the location info.

Revision history for this message
Derick Eddington (derick-eddington) wrote :

On Mon, Mar 31, 2008 at 11:26 AM, Derick Eddington
<email address hidden> wrote:
> I'm leaning
> towards syntax object with location info because of the location info.

But that's probably not possible. I was thinking &pattern would hold
a syntax object with location info of the pattern syntax, but I don't
think that's accessible when the with-syntax is running the matching
(?). A normal value / s-expr of the pattern syntax should be possible
though I think. Maybe, in addition to &pattern, &irritants could be
the datum which failed to match.

Revision history for this message
Derick Eddington (derick-eddington) wrote :

Bump :) I was just tracking down a vague "invalid syntax" from deep inside a macro with a series of with-syntax with similar looking syntax objects, and an &assertion about which specific pattern and value failed would be have been way helpful. After reviewing the previous comments, I'm thinking the &irritants should be the value/syntax-object and there should be a &pattern for the pattern form. If this could be done, it will be super awesome.

Since with-syntax expands to a syntax-case which processes all the with-syntax's patterns/expressions as one list, when a with-syntax fails, the entire expression list is the shown &syntax's "form" and this really confused me at first.

It would be great if a similar "failed to match" error would happen for syntax-case, and since with-syntax is really syntax-case, maybe the pattern failure reportings could be consolidated in syntax-case-transformer using some "who" arg/param.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Bumped.

Changed in ikarus:
importance: Low → High
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed in revision 1467. You now get:

> (with-syntax ([a #'()])
    (with-syntax ([(b) #'a]) #'b))
Unhandled exception
 Condition components:
   1. &assertion
   2. &who: with-syntax
   3. &message: "pattern does not match value"
   4. &irritants: ((b) #<syntax ()>)

Changed in ikarus:
status: Confirmed → Fix Committed
Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.