Indeed.

But it feels like that an incomplete type as type parameter should be ok if
we are never instantiating it, and only using pointers to it. From what I
see this was not considered in https://go.dev/issue/54765.

Should this be raised as an issue for 1.21 or a 1.20.1 ? Any thoughts ?



On Fri, Feb 17, 2023 at 12:43 AM Ian Lance Taylor <i...@golang.org> wrote:

> On Thu, Feb 16, 2023 at 2:38 AM Jan <pfei...@gmail.com> wrote:
> >
> > Apologies, actually it was trickier than I thought, the issue happens in
> not fully defined C types only. So here is an example that runs in go
> 1.19.5, but fails in go 1.20
> >
> > ```
> > package main
> >
> > /*
> > // Forward reference of C++ types.
> > struct SomeType;
> > typedef struct SomeType SomeType;
> >
> > // Fully defined type.
> > typedef struct {
> > char C;
> > } FullyDefinedType;
> > */
> > import "C"
> > import (
> > "fmt"
> > )
> >
> > type Wrapper[T any] struct {
> > P *T
> > }
> >
> > type SomeTypeHolder struct {
> > *Wrapper[C.SomeType]
> > }
> >
> > type FullyDefinedTypeHolder struct {
> > *Wrapper[C.FullyDefinedType]
> > }
> >
> > func main() {
> > //var p *C.SomeType
> > var x SomeTypeHolder
> > var y FullyDefinedTypeHolder
> > fmt.Printf("x.Wrapper=%x\n", x.Wrapper)
> > fmt.Printf("y.Wrapper=%x\n", y.Wrapper)
> > }
> > ```
> >
> > In go 1.19.5 it prints:
> >
> > $ go run .
> > x.Wrapper=0
> > y.Wrapper=0
> >
> > In go 1.20 it prints:
> >
> > $ go run .
> > # ...
> > ./main.go:22:3: cannot use incomplete (or unallocatable) type as a type
> argument: main._Ctype_struct_SomeType
>
> Giving an error here is https://go.dev/issue/54765.  That is, fixing
> that issue in 1.20 is what causes this program to not compile.
>
> Ian
>


-- 
Jan Pfeifer
Research Engineer
Google Switzerland GmbH
@ : pfei...@gmail.com
@ : ja...@google.com
T : +41 79 907 3855

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAE%3D7LsX9%2BOrnJ0kCFSEn_xGD%2BydK%3Dxhe4NkywjMHrKvTfFFAew%40mail.gmail.com.

Reply via email to