mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
![Robert Griesemer](/assets/img/avatar_default.png)
Two interface types that are assignable don't have to be identical; specifically, if they are defined types, they can be different defined types. If those defined types specify type parameters which are never used, do not infer a type argument based on the instantiation of a matching defined type. Adjusted three existing tests where we inferred type arguments incorrectly. Fixes #60377. Change-Id: I91fb207235424b3cbc42b5fd93eee619e7541cb7 Reviewed-on: https://go-review.googlesource.com/c/go/+/498315 Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
43 lines
665 B
Go
43 lines
665 B
Go
// run
|
|
|
|
// Copyright 2022 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 main
|
|
|
|
type TaskInput interface {
|
|
deps() []*taskDefinition
|
|
}
|
|
|
|
type Value[T any] interface {
|
|
metaValue
|
|
}
|
|
|
|
type metaValue interface {
|
|
TaskInput
|
|
}
|
|
|
|
type taskDefinition struct {
|
|
}
|
|
|
|
type taskResult struct {
|
|
task *taskDefinition
|
|
}
|
|
|
|
func (tr *taskResult) deps() []*taskDefinition {
|
|
return nil
|
|
}
|
|
|
|
func use[T any](v Value[T]) {
|
|
_, ok := v.(*taskResult)
|
|
if !ok {
|
|
panic("output must be *taskResult")
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
tr := &taskResult{&taskDefinition{}}
|
|
use[string](Value[string](tr))
|
|
}
|