]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: removed gcCompat code needed to pass orig. tests
authorRobert Griesemer <gri@golang.org>
Fri, 10 Feb 2017 00:00:23 +0000 (16:00 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 10 Feb 2017 01:22:30 +0000 (01:22 +0000)
The gcCompat mode was introduced to match the new parser's node position
setup exactly with the positions used by the original parser. Some of the
gcCompat adjustments were required to satisfy syntax error test cases,
and the rest were required to make toolstash cmp pass.

This change removes the former gcCompat adjustments and instead adjusts
the respective test cases as necessary. In some cases this makes the error
lines consistent with the ones reported by gccgo.

Where it has changed, the position associated with a given syntactic construct
is the position (line/col number) of the left-most token belonging to the
construct.

Change-Id: I5b60c00c5999a895c4d6d6e9b383c6405ccf725c
Reviewed-on: https://go-review.googlesource.com/36695
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/syntax/parser.go
src/runtime/trace/trace_stack_test.go
test/fixedbugs/issue16369.go
test/fixedbugs/issue9432.go
test/import5.go
test/import6.go [new file with mode: 0644]
test/live.go
test/switch5.go
test/typeswitch2.go

index c1faa2789444e8fb6ad0a8d9996326ea7708faed..a11be9717c763ab411390f7950f02cfff7643e76 100644 (file)
@@ -358,7 +358,7 @@ func (p *parser) importDecl(group *Group) Decl {
                d.LocalPkgName = n
                p.next()
        }
-       if p.tok == _Literal && (gcCompat || p.kind == StringLit) {
+       if p.tok == _Literal && p.kind == StringLit {
                d.Path = p.oliteral()
        } else {
                p.syntax_error("missing import path; require quoted string")
@@ -637,16 +637,13 @@ func (p *parser) callStmt() *CallStmt {
 
        s := new(CallStmt)
        s.init(p)
-       s.Tok = p.tok
+       s.Tok = p.tok // _Defer or _Go
        p.next()
 
        x := p.pexpr(p.tok == _Lparen) // keep_parens so we can report error below
        switch x := x.(type) {
        case *CallExpr:
                s.Call = x
-               if gcCompat {
-                       s.node = x.node
-               }
        case *ParenExpr:
                p.error(fmt.Sprintf("expression in %s must not be parenthesized", s.Tok))
                // already progressed, no need to advance
@@ -1127,9 +1124,6 @@ func (p *parser) structType() *StructType {
                        break
                }
        }
-       if gcCompat {
-               typ.init(p)
-       }
        p.want(_Rbrace)
 
        return typ
@@ -1154,9 +1148,6 @@ func (p *parser) interfaceType() *InterfaceType {
                        break
                }
        }
-       if gcCompat {
-               typ.init(p)
-       }
        p.want(_Rbrace)
 
        return typ
@@ -1554,8 +1545,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
                return p.newAssignStmt(0, lhs, p.exprList())
 
        case _Define:
-               var n node
-               n.init(p)
+               pos := p.pos()
                p.next()
 
                if rangeOk && p.got(_Range) {
@@ -1580,9 +1570,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
                }
 
                as := p.newAssignStmt(Def, lhs, rhs)
-               if gcCompat {
-                       as.node = n
-               }
+               as.pos = pos // TODO(gri) pass this into newAssignStmt
                return as
 
        default:
@@ -1856,9 +1844,6 @@ func (p *parser) caseClause() *CaseClause {
                p.advance(_Case, _Default, _Rbrace)
        }
 
-       if gcCompat {
-               c.init(p)
-       }
        p.want(_Colon)
        c.Body = p.stmtList()
 
index c37b33de862fee8df033345903eec33f350d006a..f8abf66500eac4271cac9cf30b1902b22d049c35 100644 (file)
@@ -151,7 +151,7 @@ func TestTraceSymbolize(t *testing.T) {
                        {"testing.tRunner", 0},
                }},
                {trace.EvGoCreate, []frame{
-                       {"runtime/trace_test.TestTraceSymbolize", 39},
+                       {"runtime/trace_test.TestTraceSymbolize", 37},
                        {"testing.tRunner", 0},
                }},
                {trace.EvGoStop, []frame{
index bd03fbc6c980f8f64d6a09783078fda61040d6bd..3ff2e6334189ba70080ed4479aee89c1ac3bf644 100644 (file)
@@ -7,7 +7,7 @@
 package p
 
 type T interface {
-       M(interface {
+       M(interface { // ERROR "cannot export unnamed recursive interface"
                T
-       }) // ERROR "cannot export unnamed recursive interface"
+       })
 }
index 20494604f7bed49048aa40cc8fad3a40d5544a15..e8946a5be25cbd190674cc89e85b44af26bc89a6 100644 (file)
@@ -9,7 +9,7 @@
 // See golang.org/issue/9432.
 package p
 
-type foo struct { // GCCGO_ERROR "invalid recursive type"
+type foo struct { // ERROR "invalid recursive type"
        bar  foo
        blah foo
-} // ERROR "invalid recursive type foo"
+}
index 6480acff92c52ea36ecb5cb54c30f1006f12142a..d9673cfe9f8eb2b948397a3b4dbbeb1d7b196eeb 100644 (file)
@@ -21,35 +21,7 @@ import _ "go/parser"
 //import "greek/αβ"
 
 // Import paths must be strings.
-import 42    // ERROR "import statement"
-import 'a'   // ERROR "import statement"
-import 3.14  // ERROR "import statement"
-import 0.25i // ERROR "import statement"
-
-// Each of these pairs tests both `` vs "" strings
-// and also use of invalid characters spelled out as
-// escape sequences and written directly.
-// For example `"\x00"` tests import "\x00"
-// while "`\x00`" tests import `<actual-NUL-byte>`.
-import ""         // ERROR "import path"
-import ``         // ERROR "import path"
-import "\x00"     // ERROR "import path"
-import `\x00`     // ERROR "import path"
-import "\x7f"     // ERROR "import path"
-import `\x7f`     // ERROR "import path"
-import "a!"       // ERROR "import path"
-import `a!`       // ERROR "import path"
-import "a b"      // ERROR "import path"
-import `a b`      // ERROR "import path"
-import "a\\b"     // ERROR "import path"
-import `a\\b`     // ERROR "import path"
-import "\"`a`\""  // ERROR "import path"
-import `\"a\"`    // ERROR "import path"
-import "\x80\x80" // ERROR "import path"
-import `\x80\x80` // ERROR "import path"
-import "\xFFFD"   // ERROR "import path"
-import `\xFFFD`   // ERROR "import path"
-
-// Invalid local imports.
-import "/foo"  // ERROR "import path cannot be absolute path"
-import "c:/foo"  // ERROR "import path contains invalid character"
+import 42    // ERROR "missing import path; require quoted string"
+import 'a'   // ERROR "missing import path; require quoted string"
+import 3.14  // ERROR "missing import path; require quoted string"
+import 0.25i // ERROR "missing import path; require quoted string"
diff --git a/test/import6.go b/test/import6.go
new file mode 100644 (file)
index 0000000..c19280f
--- /dev/null
@@ -0,0 +1,38 @@
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that invalid imports are rejected by the compiler.
+// Does not compile.
+
+package main
+
+// Each of these pairs tests both `` vs "" strings
+// and also use of invalid characters spelled out as
+// escape sequences and written directly.
+// For example `"\x00"` tests import "\x00"
+// while "`\x00`" tests import `<actual-NUL-byte>`.
+import ""         // ERROR "import path"
+import ``         // ERROR "import path"
+import "\x00"     // ERROR "import path"
+import `\x00`     // ERROR "import path"
+import "\x7f"     // ERROR "import path"
+import `\x7f`     // ERROR "import path"
+import "a!"       // ERROR "import path"
+import `a!`       // ERROR "import path"
+import "a b"      // ERROR "import path"
+import `a b`      // ERROR "import path"
+import "a\\b"     // ERROR "import path"
+import `a\\b`     // ERROR "import path"
+import "\"`a`\""  // ERROR "import path"
+import `\"a\"`    // ERROR "import path"
+import "\x80\x80" // ERROR "import path"
+import `\x80\x80` // ERROR "import path"
+import "\xFFFD"   // ERROR "import path"
+import `\xFFFD`   // ERROR "import path"
+
+// Invalid local imports.
+import "/foo"  // ERROR "import path cannot be absolute path"
+import "c:/foo"  // ERROR "import path contains invalid character"
index 0f2d81336d7bb609b0be17e9af844f979733d671..04669562548d1d60c1e2a014a91e2a4543e6c281 100644 (file)
@@ -679,9 +679,9 @@ type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "li
 // In particular, at printint r must be live.
 func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
        r = p
-       defer func() {
+       defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
                recover()
-       }() // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
+       }()
        printint(0) // ERROR "live at call to printint: q r$"
        r = q
        return // ERROR "live at call to deferreturn: r$"
index 5ca53ba7245e6cdd5422c131504100481ef6730f..5c3b28f180f4ea2a10e8cc605d0d9609f5127960 100644 (file)
@@ -67,9 +67,9 @@ func f4(e interface{}) {
        case struct {
                i int "tag2"
        }:
-       case struct {
+       case struct { // ERROR "duplicate case struct { i int .tag1. } in type switch"
                i int "tag1"
-       }: // ERROR "duplicate case struct { i int .tag1. } in type switch"
+       }:
        }
 }
 
index 6c703076a6f4908fb53cbe8446e6449bf20de8e2..1160b62e140fb72511f7f45ff3d37f05639c07de 100644 (file)
@@ -26,10 +26,10 @@ func whatis(x interface{}) string {
                w()
        }:
                return "rw"
-       case interface {        // GCCGO_ERROR "duplicate"
+       case interface {        // ERROR "duplicate"
                w()
                r()
-       }: // GC_ERROR "duplicate"
+       }:
                return "wr"
 
        }