Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccgo/gollvm: incorrect finalization of ambiguous promoted methods #52870

Closed
AblakatovMikhail opened this issue May 12, 2022 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@AblakatovMikhail
Copy link

If a type that is stored directly in an interface data word includes ambiguous promoted methods, finalization of its methods results in error: incompatible type for receiver (cannot use type <A> as type <B>).

What version of Go are you using (go version)?

$ go version
go version unknown linux/amd64
llvm-project/llvm/tools/gollvm$ git log --oneline | head -n 1
0e34e09 gollvm: add /usr/{lib,lib32} to toolchain paths for arch linux
llvm-project/llvm/tools/gollvm/gofrontend$ git log --oneline | head -n 1
6a33e7e3 compiler: remove Array_index_expression::is_lvalue_

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

The issue may be reproduced with the following sample:

foo/foo.go

package foo

import "bar"

type Foo struct {
        *bar.Bar
}

func (f *Foo) Personal(a int) error {
        return nil
}

bar/bar.go

package bar

import "baz"

type Bar struct {
        baz.Baz1
        baz.Baz2
}

baz/baz1.go

package baz

type Baz1 int32

func (b Baz1) Promoted() int {
        return 1
}

baz/baz2.go

package baz

type Baz2 int32

func (b Baz2) Promoted() int {
        return 2
}

What did you expect to see?

No error, successful build.

What did you see instead?

An attempt to build this sample results in:

$ GO111MODULE=off go build foo
# foo
foo/foo.go:5:6: error: incompatible type for receiver (cannot use type Foo as type baz.Baz1)
@gopherbot gopherbot added this to the Gccgo milestone May 12, 2022
@AblakatovMikhail
Copy link
Author

I'll submit a fix for this issue soon.

cc @ianlancetaylor

@gopherbot
Copy link

Change https://go.dev/cl/405974 mentions this issue: compiler: don't generate stubs for ambiguous direct interface methods

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label May 13, 2022
@gopherbot
Copy link

Change https://go.dev/cl/412535 mentions this issue: test: add test that gofrontend fails

gopherbot pushed a commit that referenced this issue Jun 16, 2022
For #52870

Change-Id: Ic0791af4283c9e426f7cbfab0514517ff84cfa80
Reviewed-on: https://go-review.googlesource.com/c/go/+/412535
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
xionghul pushed a commit to xionghul/gcc that referenced this issue Jun 16, 2022
Current implementation checks whether it has to generate a stub method for a
promoted method of an embedded struct field in Type::build_stub_methods(). If
the promoted method is ambiguous it's simply skipped. But struct types that
can fit in an interface value (e.g. structs that consist of a single pointer
field) get a second chance in Type::build_direct_iface_stub_methods().

This patch adds the same check used by Type::build_stub_methods() to
Type::build_direct_iface_stub_methods().

Fixes golang/go#52870

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405974
realqhc pushed a commit to realqhc/gofrontend that referenced this issue Aug 4, 2022
Current implementation checks whether it has to generate a stub method for a
promoted method of an embedded struct field in Type::build_stub_methods(). If
the promoted method is ambiguous it's simply skipped. But struct types that
can fit in an interface value (e.g. structs that consist of a single pointer
field) get a second chance in Type::build_direct_iface_stub_methods().

This patch adds the same check used by Type::build_stub_methods() to
Type::build_direct_iface_stub_methods().

Fixes golang/go#52870

Change-Id: If679e7bda8793b3cdc411419806fa36d5536faa4
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405974
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
@golang golang locked and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants