Skip to content

Commit 34f7622

Browse files
committed
[dev.go2go] go/types: make sure arrays, slices always have an element type
Addresses crash #19 of #39634. Updates #39634. Change-Id: I42208511a3fc27432891243dcf4799e80432c2c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/240903 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 6e86f51 commit 34f7622

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/go/types/expr.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,13 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
14231423
goto Error
14241424
}
14251425

1426+
// In pathological (invalid) cases (e.g.: type T1 [][[]T1{}[0][0]]T0)
1427+
// the element type may be accessed before it's set. Make sure we have
1428+
// a valid type.
1429+
if x.typ == nil {
1430+
x.typ = Typ[Invalid]
1431+
}
1432+
14261433
check.index(e.Index, length)
14271434
// ok to continue
14281435

src/go/types/fixedbugs/issue39634.go2

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
package p
66

77
// crash 1
8-
type nt(type )interface{g /* ERROR undeclared name */ }
9-
type ph(type e nt,g(d /* ERROR undeclared name */ ))s /* ERROR undeclared name */
10-
func(*ph(e,e /* ERROR redeclared */ ))h(d /* ERROR undeclared name */ )
8+
type nt1(type )interface{g /* ERROR undeclared name */ }
9+
type ph1(type e nt1,g(d /* ERROR undeclared name */ ))s /* ERROR undeclared name */
10+
func(*ph1(e,e /* ERROR redeclared */ ))h(d /* ERROR undeclared name */ )
1111

1212
// crash 2
13-
type Numeric2 interface{t /* ERROR not a type */ }
14-
func t(type T Numeric2)(s[]T){0 /* ERROR not a type */ (){s /* ERROR cannot index */ [0][0]}}
13+
type Numeric2 interface{t2 /* ERROR not a type */ }
14+
func t2(type T Numeric2)(s[]T){0 /* ERROR not a type */ (){s /* ERROR cannot index */ [0][0]}}
1515

1616
// crash 4
1717
type Numeric4 interface{t4 /* ERROR not a type */ }
@@ -35,6 +35,9 @@ type Z17 interface {
3535
}
3636
func F17(type T Z17)(T)
3737

38+
// crash 19
39+
type Z19 [][[]Z19{}[0][0]]c19 /* ERROR undeclared */
40+
3841
// crash 20
3942
type Z20 /* ERROR illegal cycle */ interface{ Z20 }
4043
func F20(type t Z20)() { F20(t /* ERROR invalid composite literal type */ {}) }

0 commit comments

Comments
 (0)