Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types, types2: infinite recursion if constraint type and type param have same name #50321

Closed
ArnaudCelermajer opened this issue Dec 23, 2021 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@ArnaudCelermajer
Copy link

ArnaudCelermajer commented Dec 23, 2021

What version of Go are you using (go version)?

$ go version
Go 1.18 Beta 1  

Does this issue reproduce with the latest release?

on Beta

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
I presume the The Go Playground run under linux docker

What did you do?

package main
import "fmt"
type Arno interface {
	int | string
}
func Ln[Arno Arno](p Arno) {
	fmt.Println(p)
}
func main() {
	Ln("Salut")
	Ln(123)
}

What did you expect to see?

print of

Salut
123

or

Build fail "Arno isn't a good name use Arnaud instead" /// or an other error message ;-) 

What did you see instead?

`runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc0203e0380 stack=[0xc0203e0000, 0xc0403e0000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xd20d63?, 0x12ea300?})
/usr/local/go/src/runtime/panic.go:992 +0x71
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1101 +0x5cc
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:547 +0x8b

goroutine 1 [running]:
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:23 +0x71 fp=0xc0203e0390 sp=0xc0203e0388 pc=0xb94ab1
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e03e8 sp=0xc0203e0390 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0400 sp=0xc0203e03e8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0418 sp=0xc0203e0400 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0470 sp=0xc0203e0418 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0488 sp=0xc0203e0470 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e04a0 sp=0xc0203e0488 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e04f8 sp=0xc0203e04a0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0510 sp=0xc0203e04f8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0528 sp=0xc0203e0510 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0580 sp=0xc0203e0528 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0598 sp=0xc0203e0580 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e05b0 sp=0xc0203e0598 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0608 sp=0xc0203e05b0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0620 sp=0xc0203e0608 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0638 sp=0xc0203e0620 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0690 sp=0xc0203e0638 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e06a8 sp=0xc0203e0690 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e06c0 sp=0xc0203e06a8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0718 sp=0xc0203e06c0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0730 sp=0xc0203e0718 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0748 sp=0xc0203e0730 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e07a0 sp=0xc0203e0748 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e07b8 sp=0xc0203e07a0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e07d0 sp=0xc0203e07b8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0828 sp=0xc0203e07d0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0840 sp=0xc0203e0828 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0858 sp=0xc0203e0840 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e08b0 sp=0xc0203e0858 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e08c8 sp=0xc0203e08b0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e08e0 sp=0xc0203e08c8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0938 sp=0xc0203e08e0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0950 sp=0xc0203e0938 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0968 sp=0xc0203e0950 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e09c0 sp=0xc0203e0968 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e09d8 sp=0xc0203e09c0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e09f0 sp=0xc0203e09d8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0a48 sp=0xc0203e09f0 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0a60 sp=0xc0203e0a48 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0a78 sp=0xc0203e0a60 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0ad0 sp=0xc0203e0a78 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0ae8 sp=0xc0203e0ad0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0b00 sp=0xc0203e0ae8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0b58 sp=0xc0203e0b00 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0b70 sp=0xc0203e0b58 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0b88 sp=0xc0203e0b70 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0be0 sp=0xc0203e0b88 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0bf8 sp=0xc0203e0be0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0c10 sp=0xc0203e0bf8 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0c68 sp=0xc0203e0c10 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0c80 sp=0xc0203e0c68 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0c98 sp=0xc0203e0c80 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0cf0 sp=0xc0203e0c98 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0d08 sp=0xc0203e0cf0 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0d20 sp=0xc0203e0d08 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0d78 sp=0xc0203e0d20 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0d90 sp=0xc0203e0d78 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0da8 sp=0xc0203e0d90 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0e00 sp=0xc0203e0da8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0e18 sp=0xc0203e0e00 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0e30 sp=0xc0203e0e18 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0e88 sp=0xc0203e0e30 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0ea0 sp=0xc0203e0e88 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0eb8 sp=0xc0203e0ea0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0f10 sp=0xc0203e0eb8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0f28 sp=0xc0203e0f10 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0f40 sp=0xc0203e0f28 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e0f98 sp=0xc0203e0f40 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e0fb0 sp=0xc0203e0f98 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e0fc8 sp=0xc0203e0fb0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e1020 sp=0xc0203e0fc8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1038 sp=0xc0203e1020 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1050 sp=0xc0203e1038 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e10a8 sp=0xc0203e1050 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e10c0 sp=0xc0203e10a8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e10d8 sp=0xc0203e10c0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e1130 sp=0xc0203e10d8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1148 sp=0xc0203e1130 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1160 sp=0xc0203e1148 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e11b8 sp=0xc0203e1160 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e11d0 sp=0xc0203e11b8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e11e8 sp=0xc0203e11d0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e1240 sp=0xc0203e11e8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1258 sp=0xc0203e1240 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1270 sp=0xc0203e1258 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e12c8 sp=0xc0203e1270 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e12e0 sp=0xc0203e12c8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e12f8 sp=0xc0203e12e0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e1350 sp=0xc0203e12f8 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1368 sp=0xc0203e1350 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1380 sp=0xc0203e1368 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e13d8 sp=0xc0203e1380 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e13f0 sp=0xc0203e13d8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1408 sp=0xc0203e13f0 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e1460 sp=0xc0203e1408 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1478 sp=0xc0203e1460 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1490 sp=0xc0203e1478 pc=0xb94a98
cmd/compile/internal/types2.(*TypeParam).iface(0xc00038d9b0)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:104 +0x37 fp=0xc0203e14e8 sp=0xc0203e1490 pc=0xb956d7
cmd/compile/internal/types2.(*TypeParam).Underlying(0x0?)
/usr/local/go/src/cmd/compile/internal/types2/typeparam.go:88 +0x19 fp=0xc0203e1500 sp=0xc0203e14e8 pc=0xb95619
cmd/compile/internal/types2.under({0xe8d760?, 0xc00038d9b0?})
/usr/local/go/src/cmd/compile/internal/types2/type.go:27 +0x58 fp=0xc0203e1518 sp=0xc0203e1500 pc=0xb94a98
...additional frames elided...

Go build failed.`

@danscales
Copy link
Contributor

@griesemer @findleyr Infinite recursion in types2, because of the use of 'Arno' for both the constraint interface type and the name of the type param. Everything builds and runs fine if the type param Arno is renamed to 'T'.

func Ln[T Arno](p T) {
	fmt.Println(p)
}

@danscales danscales changed the title affected/package: "cmd/compile/internal/types2.under" Generics: Interface with constraints go/types, type2: infinite recursion if constraint type and type param have same name Dec 23, 2021
@findleyr findleyr added this to the Go1.18 milestone Dec 23, 2021
@danscales danscales changed the title go/types, type2: infinite recursion if constraint type and type param have same name go/types, types2: infinite recursion if constraint type and type param have same name Dec 23, 2021
@findleyr findleyr self-assigned this Dec 23, 2021
@findleyr findleyr added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Dec 23, 2021
@findleyr
Copy link
Contributor

findleyr commented Dec 23, 2021

Thanks very much for this report! I'm surprised we haven't hit this bug before. I know we've been trying to avoid assigning the release-blocker label for bugs compiling invalid code, but given that this is an infinite recursion I think it is warranted here (and the corresponding bug in go/types would crash tools).

Looking now.

@gopherbot
Copy link

Change https://golang.org/cl/374294 mentions this issue: go/types, types2: eagerly check that constraints are not type params

@go101
Copy link

go101 commented Dec 23, 2021

It printed an error before beta: https://groups.google.com/g/golang-nuts/c/Zt0pstrpS50/m/kqejC67FCAAJ

@go101
Copy link

go101 commented Dec 23, 2021

I don't know whether or not the spec has specified the scope of a type parameter.
From the current implementation, it looks type parameters are declared in the top local block.

func Bar[T any](x T) T {
   var T = x // T redeclared in this block
   return T
}

func Bar2[T any](x T) T {
   {
     var T = x // okay
     return T
   }
}

@findleyr
Copy link
Contributor

@go101 the issue here is simply a bug in type checking type parameters that are used as their own constraint, as in the type parameter list [T T]. Some recent changes caused this to fall into an infinite recursion, fixed by https://golang.org/cl/374294.

Type parameters are scoped to the declaration in which they are defined. The spec is still in-progress and may not reflect this yet.

jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
As a result of the change to the underlying of a type parameter to be
its constraint interface, we had couple inaccuracies that combined to
cause an infinite recursion when type checking the invalid type
parameter list [A A].
 - We deferred tpar.iface() using check.later twice: once in
   newTypeParam, and then again at the end of collectTypeParams.
 - We deferred the check that type parameter constraints are not type
   parameters, even though this is unnecessary: the constraint type is
   known.

With these inaccuracies, tpar.iface() was executing before our guard
against using type parameters as constraints, causing an infinite
recursion through under().

Fix this by eagerly checking whether the constraint is a type
parameter, and marking it invalid if so. Also remove the unnecessary
calls to tpar.iface() at the end of collectTypeParams, as this will
already have been scheduled by newTypeParam.

Fixes golang#50321

Change-Id: I4eecbecf21656615867cb94be65b520e9e795bd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/374294
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants