Skip to content

Commit

Permalink
[dev.go2go] go/types: don't modify Named.underlying when checking val…
Browse files Browse the repository at this point in the history
…idity

Addresses crash #20 of #39634.
Added test, also for some of the other cases that don't crash
anymore.

Updates #39634.

Change-Id: I999e376985a443ac435f64a7c249f891e7b7a6d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/240901
Reviewed-by: Robert Griesemer <gri@golang.org>
  • Loading branch information
griesemer committed Jul 3, 2020
1 parent 4dde96e commit 167909e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/go/types/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var tests = [][]string{
// Go 2 prototype bug fixes
// TODO(gri) Eliminate the need to enumerate these tests here.
// Should just traverse that directory.
{"fixedbugs/issue39634.go2"},
{"fixedbugs/issue39664.go2"},
{"fixedbugs/issue39680.go2"},
{"fixedbugs/issue39693.go2"},
Expand Down
1 change: 0 additions & 1 deletion src/go/types/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
if tn == t.obj {
check.cycleError(path[i:])
t.info = invalid
t.underlying = Typ[Invalid]
return t.info
}
}
Expand Down
44 changes: 44 additions & 0 deletions src/go/types/fixedbugs/issue39634.go2
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2020 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.

package p

// crash 1
type nt(type )interface{g /* ERROR undeclared name */ }
type ph(type e nt,g(d /* ERROR undeclared name */ ))s /* ERROR undeclared name */
func(*ph(e,e /* ERROR redeclared */ ))h(d /* ERROR undeclared name */ )

// crash 2
type Numeric2 interface{t /* ERROR not a type */ }
func t(type T Numeric2)(s[]T){0 /* ERROR not a type */ (){s /* ERROR cannot index */ [0][0]}}

// crash 4
type Numeric4 interface{t4 /* ERROR not a type */ }
func t4(type T Numeric4)(s[]T){if( /* ERROR non-boolean */ 0){*s /* ERROR cannot indirect */ [0]}}

// crash 7
type foo7 interface { bar() }
type x7(type A) struct{ foo7 }
func main7() { var _ foo7 = x7(int){} }

// crash 8
type foo8(type A) interface { type A }
func bar8(type A foo8(A))(a A) {}
func main8() {}

// crash 17
type Y17 interface{ c() }
type Z17 interface {
c() Y17
Y17 /* ERROR duplicate method */
}
func F17(type T Z17)(T)

// crash 20
type Z20 /* ERROR illegal cycle */ interface{ Z20 }
func F20(type t Z20)() { F20(t /* ERROR invalid composite literal type */ {}) }

// crash 21
type Z21 /* ERROR illegal cycle */ interface{ Z21 }
func F21(type *T Z21)() { ( /* ERROR not used */ F21(Z21)) }

0 comments on commit 167909e

Please sign in to comment.