unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH] Fix error messages involving internal definitions
Date: Fri, 27 Jan 2012 12:27:16 +0100	[thread overview]
Message-ID: <87obtpgzcb.fsf@pobox.com> (raw)
In-Reply-To: <87sjj1obca.fsf@netris.org> (Mark H. Weaver's message of "Fri, 27 Jan 2012 02:26:13 -0500")

Hi Mark!

Thanks for tracking down this issue.  I'm sure it will make it in 2.0.4,
but I do have a couple questions.

On Fri 27 Jan 2012 08:26, Mark H Weaver <mhw@netris.org> writes:

> So, what does this fix?  The "definition in expression context" error
> message is broken in several ways.  First of all, source location
> information is _never_ provided if the rhs expression is an atom, even
> when compiling a module in the normal way.

Indeed.  In fact that was the reason for this terrible misguided hack:

> Secondly, instead of printing the definition form, it
> reports the identifier as the 'subform', and the rhs expression as the
> 'form'.

Since I knew the identifier would not carry source properties, I threw
the RHS into the error on the off chance that it would have source
properties, and could help the user track down the error.  But this led
to bad error messages even in the best case of the RHS being a pair...

> Thirdly, "definition in expression context" is a confusing message for
> Scheme beginners, who are likely to make this mistake.

The problem is that I'm not sure that the error message you suggest is
correct.  You show:

>   (let ((x 1))
>     #f
>     (define blah 3))
>
> Currently, you get a message like this:
>
>   unknown location: definition in expression context in subform blah of 3
>
> With this patch, you get a message like this:
>
>   /home/mhw/guile-modules/foo.scm:5:2: internal definition in a context where definitions are not allowed in form (define blah 3)

And this is much better.  But, it is not the right error message for a
form like:

  (if 1
      (define bar 2))

So, that's question 1: can we come up with some other message that's
more helpful while also being accurate?

"Definition in expression context" does have the advantage that it can
be searched for in the manual (if we put it there), or on the web.  If
all things were equal, it would have the advantage of being shorter as
well.

Question 2 is about the implementation.  I'm sure you winced as much as
I did at adding a seventh return value from syntax-type :)  I was
reading though and noted in the comment above syntax-type that the "s"
return value already has the source information for the expression.  So
a more minimal change like the attached patch yields the error message:

  /tmp/foo.scm:5:2: definition in expression context in form blah

WDYT?  I think I prefer the more minimal approach in that patch, but
either way is fine.

Feel free to commit whatever you think is best, here.

Andy

diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
index 20ea8eb..46883fe 100644
--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -1319,13 +1319,13 @@
                     (expand-void))))))
           ((define-form define-syntax-form define-syntax-parameter-form)
            (syntax-violation #f "definition in expression context"
-                             e (wrap value w mod)))
+                             value #:source s))
           ((syntax)
            (syntax-violation #f "reference to pattern variable outside syntax form"
-                             (source-wrap e w s mod)))
+                             e #:source s))
           ((displaced-lexical)
            (syntax-violation #f "reference to identifier outside its scope"
-                             (source-wrap e w s mod)))
+                             e #:source s))
           (else (syntax-violation #f "unexpected syntax"
                                   (source-wrap e w s mod))))))
 
@@ -2542,12 +2542,12 @@
             (bound-id=? x y)))
 
     (set! syntax-violation
-          (lambda* (who message form #:optional subform)
+          (lambda* (who message form #:optional subform
+                        #:key (source (source-annotation (or form subform))))
             (arg-check (lambda (x) (or (not x) (string? x) (symbol? x)))
                        who 'syntax-violation)
             (arg-check string? message 'syntax-violation)
-            (throw 'syntax-error who message
-                   (source-annotation (or form subform))
+            (throw 'syntax-error who message source
                    (strip form empty-wrap)
                    (and subform (strip subform empty-wrap)))))
 

-- 
http://wingolog.org/



  parent reply	other threads:[~2012-01-27 11:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-27  7:26 [PATCH] Fix error messages involving internal definitions Mark H Weaver
2012-01-27  7:58 ` Mark H Weaver
2012-01-27 11:27 ` Andy Wingo [this message]
2012-01-27 14:26   ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87obtpgzcb.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).