]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix line number at EOF
authorRuss Cox <rsc@golang.org>
Sat, 23 Apr 2011 14:54:05 +0000 (10:54 -0400)
committerRuss Cox <rsc@golang.org>
Sat, 23 Apr 2011 14:54:05 +0000 (10:54 -0400)
Fixes #1474.

R=ken2
CC=golang-dev
https://golang.org/cl/4432061

src/cmd/gc/go.h
src/cmd/gc/lex.c
test/fixedbugs/bug332.go [new file with mode: 0644]

index 042856b45994fb15719c8bb7158d176b990a0d9a..58f8acecbe15c6e33b45f6831cc19f2899d8faf5 100644 (file)
@@ -582,6 +582,7 @@ struct      Io
        Biobuf* bin;
        int32   ilineno;
        int     nlsemi;
+       int     eofnl;
        int     peekc;
        int     peekc1; // second peekc for ...
        char*   cp;     // used for content when bin==nil
index bfd96274edeefa5396719318b33c2edd935d58d7..18803938ddc609cd5325980adb2fc388b3de16b1 100644 (file)
@@ -1310,7 +1310,7 @@ getc(void)
                        lexlineno++;
                return c;
        }
-
+       
        if(curio.bin == nil) {
                c = *curio.cp & 0xff;
                if(c != 0)
@@ -1325,8 +1325,11 @@ getc(void)
                        break;
                }
        case EOF:
-               return EOF;
-
+               // insert \n at EOF
+               if(curio.eofnl)
+                       return EOF;
+               curio.eofnl = 1;
+               c = '\n';
        case '\n':
                if(pushedio.bin == nil)
                        lexlineno++;
diff --git a/test/fixedbugs/bug332.go b/test/fixedbugs/bug332.go
new file mode 100644 (file)
index 0000000..be79286
--- /dev/null
@@ -0,0 +1,17 @@
+// errchk $G $D/$F.go
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// type T int
+
+func main() {}
+
+// issue 1474
+
+// important: no newline on end of next line.
+// 6g used to print <epoch> instead of bug332.go:111 
+func (t *T) F() {} // ERROR "bug332"
\ No newline at end of file