Skip to content

Commit e531e11

Browse files
[dev.go2go] go/go2go: return quickly from typeWithoutArgs if no args
Avoids crashing when we see a universe scope type in an instantiated type. Change-Id: Iec3ebee291973180a63cd4cddef7e2f131a30053 Reviewed-on: https://go-review.googlesource.com/c/go/+/238622 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 9840dbb commit e531e11

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/go/go2go/rewrite.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,9 @@ func (t *translator) lookupInstantiatedType(typ *types.Named) (types.Type, *ast.
959959
// typeWithoutArgs takes a named type with arguments and returns the
960960
// same type without arguments.
961961
func (t *translator) typeWithoutArgs(typ *types.Named) *types.Named {
962+
if len(typ.TArgs()) == 0 {
963+
return typ
964+
}
962965
name := typ.Obj().Name()
963966
fields := strings.Split(name, ".")
964967
if len(fields) > 2 {
@@ -969,6 +972,9 @@ func (t *translator) typeWithoutArgs(typ *types.Named) *types.Named {
969972
}
970973

971974
tpkg := typ.Obj().Pkg()
975+
if tpkg == nil {
976+
panic(fmt.Sprintf("can't find package for %s", name))
977+
}
972978
nobj := tpkg.Scope().Lookup(name)
973979
if nobj == nil {
974980
panic(fmt.Sprintf("can't find %q in scope of package %q", name, tpkg.Name()))

test/gen/g022.go2

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile
2+
3+
// Copyright 2020 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type F(type T) func(T) error
10+
11+
type instF = F(int)

0 commit comments

Comments
 (0)