Commit 7879d311 authored by Russ Cox's avatar Russ Cox

gc: fix line number at EOF

Fixes #1474.

R=ken2
CC=golang-dev
https://golang.org/cl/4432061
parent c7008f47
...@@ -582,6 +582,7 @@ struct Io ...@@ -582,6 +582,7 @@ struct Io
Biobuf* bin; Biobuf* bin;
int32 ilineno; int32 ilineno;
int nlsemi; int nlsemi;
int eofnl;
int peekc; int peekc;
int peekc1; // second peekc for ... int peekc1; // second peekc for ...
char* cp; // used for content when bin==nil char* cp; // used for content when bin==nil
......
...@@ -1310,7 +1310,7 @@ getc(void) ...@@ -1310,7 +1310,7 @@ getc(void)
lexlineno++; lexlineno++;
return c; return c;
} }
if(curio.bin == nil) { if(curio.bin == nil) {
c = *curio.cp & 0xff; c = *curio.cp & 0xff;
if(c != 0) if(c != 0)
...@@ -1325,8 +1325,11 @@ getc(void) ...@@ -1325,8 +1325,11 @@ getc(void)
break; break;
} }
case EOF: case EOF:
return EOF; // insert \n at EOF
if(curio.eofnl)
return EOF;
curio.eofnl = 1;
c = '\n';
case '\n': case '\n':
if(pushedio.bin == nil) if(pushedio.bin == nil)
lexlineno++; lexlineno++;
......
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment