Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev.go2go] go/go2go, go/types: enable constraint type inference
Constraint type inference was not enabled for go/go2go and gotype. Fixes #40859. Change-Id: Idcab4d0a2eae6f42f938604fb05aabe4ad94c934 Reviewed-on: https://go-review.googlesource.com/c/go/+/249737 Reviewed-by: Ian Lance Taylor <iant@golang.org>
- Loading branch information
Showing
3 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// compile | ||
|
||
// Copyright 2020 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. | ||
|
||
// Issue 40859. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type Number interface { | ||
type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64 | ||
} | ||
|
||
type MySlice []int | ||
|
||
type SC[type E] interface { | ||
type []E | ||
} | ||
|
||
func DoubleDefined[type S SC[E], E Number](s S) S { | ||
r := make(S, len(s)) | ||
for i, v := range s { | ||
r[i] = v + v | ||
} | ||
return r | ||
} | ||
|
||
func main() { | ||
// Expicit types work fine | ||
fmt.Println(DoubleDefined[MySlice, int](MySlice{1})) | ||
|
||
// Constraint type inference does not work? | ||
fmt.Println(DoubleDefined(MySlice{1})) | ||
} |