]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.11] go/types: handle nil pointer when panic is written outside...
authorRebecca Stambler <rstambler@golang.org>
Thu, 30 Aug 2018 15:33:19 +0000 (11:33 -0400)
committerIan Lance Taylor <iant@golang.org>
Wed, 12 Sep 2018 17:17:42 +0000 (17:17 +0000)
The current implementation crashes when someone writes a panic outside of
a function, which makes sense since that is broken code. This fix allows
one to type-check broken code.

Fixes #27497

Change-Id: I81b90dbd918162a20c60a821340898eaf02e648d
Reviewed-on: https://go-review.googlesource.com/132235
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit c99687f87aed84342cfe92ae78924f791237c6f6)
Reviewed-on: https://go-review.googlesource.com/133395
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/api_test.go
src/go/types/builtins.go

index 1fe20794ea9341b5bc85785c3634ca10e4270a5c..cde07f2b4bba6cb22e2bcff1dc7055344726cefc 100644 (file)
@@ -261,6 +261,8 @@ func TestTypesInfo(t *testing.T) {
                {`package x0; func _() { var x struct {f string}; x.f := 0 }`, `x.f`, `string`},
                {`package x1; func _() { var z string; type x struct {f string}; y := &x{q: z}}`, `z`, `string`},
                {`package x2; func _() { var a, b string; type x struct {f string}; z := &x{f: a; f: b;}}`, `b`, `string`},
+               {`package x3; var x = panic("");`, `panic`, `func(interface{})`},
+               {`package x4; func _() { panic("") }`, `panic`, `func(interface{})`},
        }
 
        for _, test := range tests {
index 05e032423ca2c84cb84c67ca5da1b81454c87c59..d3f0c4d40dfb1dead02852227521e0ca54e3ccd8 100644 (file)
@@ -476,7 +476,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // panic(x)
                // record panic call if inside a function with result parameters
                // (for use in Checker.isTerminating)
-               if check.sig.results.Len() > 0 {
+               if check.sig != nil && check.sig.results.Len() > 0 {
                        // function has result parameters
                        p := check.isPanic
                        if p == nil {