1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:34:41 -07:00

gc: fix line number at EOF

Fixes #1474.

R=ken2
CC=golang-dev
https://golang.org/cl/4432061
This commit is contained in:
Russ Cox 2011-04-23 10:54:05 -04:00
parent c7008f47ec
commit 7879d3118c
3 changed files with 24 additions and 3 deletions

View 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

View 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++;

17
test/fixedbugs/bug332.go Normal file
View File

@ -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"