The core type definition might be not right

205 views
Skip to first unread message

tapi...@gmail.com

unread,
Mar 3, 2022, 12:09:32 PM3/3/22
to golang-nuts

The tip spec states that the core type of a constraint is born from the type set of the constraint. https://tip.golang.org/ref/spec#Core_types

So the C constraint in the following program should have no core type,
because its type set is blank. But the foo function compiles okay,
which indicates the current implementation thinks C has a core type.

Maybe, the core type of a constraint should be born from the specific types of the constraint?

package main

func main() {}

type C interface {
        map[int]int
        M()
}
       
func foo[T C]() {
        var _ = make(T)
}





gri

unread,
Mar 3, 2022, 9:17:12 PM3/3/22
to golang-nuts
Thanks for bringing this up. It's a fair point.
Note though that it won't be possible to instantiate  foo because there's no type argument that would implement C; so it's not possible to get to an incorrectly running program here.
We also don't report an error when a type set is empty.
But you are correct that make(T) requires a core type which doesn't exist here and thus it should not be valid.
I filed #51470 to track this.
- gri
Reply all
Reply to author
Forward
0 new messages