golang/go

x/tools/go/types: line number out of range

dvyukov opened this issue · 4 comments

Gc rejects to compile the following program:

package a //line :1000000000

saying:

line number out of range

gotype compiles it successfully.

Compilers should agree on whether it is a valid Go program or not.

on commit af81789

The spec doesn't mention the interpretation of //line comments - this is a tool (compiler)-specific feature. I think there are 2 issues here:

  1. The compiler should probably ignore //line comments that don't start at the beginning of the line.
  2. The compiler should do something sensible when the //line comment is incorrect (as in this case).

FWIW, go/types simply ignores incorrect //line comments or //line comments with out-of-range (64bit int) line numbers.

Leaving to rsc.

I understand that this is implementation-specific, but there seems to be no point in having different behavior in different compilers here. This makes side-by-side comparison of compilers difficult.

I believe cmd/compile (gc) should accept this program. The //line comment doesn't start on the beginning of a line and should be ignored. Making this a gc bug.

Fixed in go1.8 by d390283.