bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Warning message issued with no source line number [PATCH]


From: Andrew J. Schorr
Subject: Re: [bug-gawk] Warning message issued with no source line number [PATCH]
Date: Fri, 19 May 2017 09:13:19 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Fri, May 19, 2017 at 01:26:31PM +0300, Arnold Robbins wrote:
> Your patch fixes the problem locally.

I thought so. That is why I was not comfortable with the patch.

> The following change looks to be more
> general and catches the issue.

This was my second idea if the first approach didn't work.

> The byte code for 'BEGIN { "a" }' seems to not be caught by add_lint().
> That's more work than I have time for right now.

Agreed. :-)

> Andy - does this look OK to you to commit?

It seems fine, although I do have 2 questions/comments:

1. It says:

+                               if (line == 0 && ip->source_line != 0)
+                                       line = ip->source_line;

So once "line" is set, it won't change. That gives a preference for the
a line value at the front of the list. Is that better than:

+                               if (ip->source_line != 0)
+                                       line = ip->source_line;

which would prefer the back of the list? I have no idea, but if I had done it,
I would have guessed that the back of the list should be preferred, since we
scan until the back. For this test case, both approaches give the same
result.

2. I would have put the "line" variable inside the scope of the "if" statement,
but that's basically a cosmetic decision.

Regards,
Andy

diff --git a/awkgram.y b/awkgram.y
index b72d1c8..f75d988 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -5904,12 +5904,18 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype)
 
        case LINT_no_effect:
                if (list->lasti->opcode == Op_pop && list->nexti != 
list->lasti) {
-                       for (ip = list->nexti; ip->nexti != list->lasti; ip = 
ip->nexti)
-                               ;
+                       int line = 0;
 
+                       for (ip = list->nexti; ip->nexti != list->lasti; ip = 
ip->nexti) {
+                               if (ip->source_line != 0)
+                                       line = ip->source_line;
+                       } 
                        if (do_lint) {          /* compile-time warning */
-                               if (isnoeffect(ip->opcode))
-                                       lintwarn_ln(ip->source_line, 
("statement may have no effect"));
+                               if (isnoeffect(ip->opcode)) {
+                                       if (ip->source_line != 0)
+                                               line = ip->source_line;
+                                       lintwarn_ln(line, ("statement may have 
no effect"));
+                               }
                        }
 
                        if (ip->opcode == Op_push) {            /* run-time 
warning */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]