mirror of
https://github.com/golang/go
synced 2024-11-22 07:34:40 -07:00
gc: use correct line number for EOF syntax error
I also added some debugging code that's turned on with -xx. Fixes #3392. R=rsc, lvd CC=golang-dev https://golang.org/cl/5909058
This commit is contained in:
parent
4d3db77c69
commit
42aa9abae9
@ -1531,9 +1531,7 @@ getc(void)
|
|||||||
if(c != 0) {
|
if(c != 0) {
|
||||||
curio.peekc = curio.peekc1;
|
curio.peekc = curio.peekc1;
|
||||||
curio.peekc1 = 0;
|
curio.peekc1 = 0;
|
||||||
if(c == '\n' && pushedio.bin == nil)
|
goto check;
|
||||||
lexlineno++;
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(curio.bin == nil) {
|
if(curio.bin == nil) {
|
||||||
@ -1543,6 +1541,7 @@ getc(void)
|
|||||||
} else
|
} else
|
||||||
c = Bgetc(curio.bin);
|
c = Bgetc(curio.bin);
|
||||||
|
|
||||||
|
check:
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 0:
|
case 0:
|
||||||
if(curio.bin != nil) {
|
if(curio.bin != nil) {
|
||||||
|
@ -142,6 +142,11 @@ yyerror(char *fmt, ...)
|
|||||||
if(debug['x'])
|
if(debug['x'])
|
||||||
print("yyerror: yystate=%d yychar=%d\n", yystate, yychar);
|
print("yyerror: yystate=%d yychar=%d\n", yystate, yychar);
|
||||||
|
|
||||||
|
// An unexpected EOF caused a syntax error. Use the previous
|
||||||
|
// line number since getc generated a fake newline character.
|
||||||
|
if(curio.eofnl)
|
||||||
|
lexlineno = prevlineno;
|
||||||
|
|
||||||
// only one syntax error per line
|
// only one syntax error per line
|
||||||
if(lastsyntax == lexlineno)
|
if(lastsyntax == lexlineno)
|
||||||
return;
|
return;
|
||||||
|
15
test/fixedbugs/bug435.go
Normal file
15
test/fixedbugs/bug435.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// errorcheck
|
||||||
|
|
||||||
|
// Copyright 2012 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.
|
||||||
|
|
||||||
|
// Test that a syntax error caused by an unexpected EOF
|
||||||
|
// gives an error message with the correct line number.
|
||||||
|
//
|
||||||
|
// https://code.google.com/p/go/issues/detail?id=3392
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
bar(1, // ERROR "unexpected"
|
Loading…
Reference in New Issue
Block a user