]> Cypherpunks repositories - gostls13.git/commitdiff
Fix for scanner bug (introduced with most recent change).
authorRobert Griesemer <gri@golang.org>
Wed, 16 Dec 2009 02:03:59 +0000 (18:03 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 16 Dec 2009 02:03:59 +0000 (18:03 -0800)
Fixes #433.

R=rsc
CC=golang-dev
https://golang.org/cl/179072

src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner_test.go

index fad3c0f75442ca732db7c9884937715f3d845b5a..4735cbd3b5dfd349dece11ad3bfd71918af2fd74 100644 (file)
@@ -223,10 +223,10 @@ func (S *Scanner) findNewline(pos token.Position) bool {
                }
        }
 
-       // reset position
+       // reset position to where it was upon calling findNewline
        S.pos = pos
        S.offset = pos.Offset + 1
-       S.ch = '/'
+       S.next()
 
        return newline
 }
@@ -577,6 +577,10 @@ scanAgain:
                        if S.ch == '/' || S.ch == '*' {
                                // comment
                                if S.insertSemi && S.findNewline(pos) {
+                                       // reset position to the beginning of the comment
+                                       S.pos = pos
+                                       S.offset = pos.Offset + 1
+                                       S.ch = '/'
                                        S.insertSemi = false // newline consumed
                                        return pos, token.SEMICOLON, semicolon
                                }
index 6ea4b2d58e16388f4da7877ed0149e47f6291ce0..83314a3aa1882da787618b5b29a3d1d4e5d954a1 100644 (file)
@@ -392,6 +392,8 @@ var lines = []string{
        "foo    $/*comment*/    \n",
        "foo    $/*0*/ /*1*/ /*2*/    \n",
        "foo    $/**/ /*-------------*/       /*----\n*/bar       $/*  \n*/baa",
+
+       "package main$\n\nfunc main() {\n\tif {\n\t\treturn /* */ }$\n}$\n",
 }