-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cgo: update to handle ast.IndexListExpr
Allows cgo to work with generics. Updates #47781. Change-Id: Id1a5d1a0a8193c5b157e3e671b1490d687d10384 Reviewed-on: https://go-review.googlesource.com/c/go/+/353882 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
- Loading branch information
Showing
6 changed files
with
62 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2021 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 cgotest | ||
|
||
// #include <stddef.h> | ||
import "C" | ||
|
||
func generic[T, U any](t T, u U) {} | ||
|
||
func useGeneric() { | ||
const zero C.size_t = 0 | ||
|
||
generic(zero, zero) | ||
generic[C.size_t, C.size_t](0, 0) | ||
} |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
// directory.) | ||
module misc | ||
|
||
go 1.12 | ||
go 1.18 |
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,17 @@ | ||
// Copyright 2021 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. | ||
|
||
//go:build !go1.18 | ||
// +build !go1.18 | ||
|
||
package main | ||
|
||
import ( | ||
"go/token" | ||
) | ||
|
||
func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) { | ||
error_(token.NoPos, "unexpected type %T in walk", x) | ||
panic("unexpected type") | ||
} |
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,25 @@ | ||
// Copyright 2021 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. | ||
|
||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package main | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
) | ||
|
||
func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) { | ||
switch n := x.(type) { | ||
default: | ||
error_(token.NoPos, "unexpected type %T in walk", x) | ||
panic("unexpected type") | ||
|
||
case *ast.IndexListExpr: | ||
f.walk(&n.X, ctxExpr, visit) | ||
f.walk(n.Indices, ctxExpr, visit) | ||
} | ||
} |
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