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: couldn't detect method of unnamed types #38125

Closed
dotaheor opened this issue Mar 28, 2020 · 5 comments
Closed

gccgo: couldn't detect method of unnamed types #38125

dotaheor opened this issue Mar 28, 2020 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dotaheor
Copy link

dotaheor commented Mar 28, 2020

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

$ gccgo --version
gccgo (Ubuntu 8.3.0-6) 8.3.0

Does this issue reproduce with the latest release?

True

What did you do?

package main

import (
	"fmt"
	"time"
)
	

type T = struct {
	time.Time
}

func main() {
	fmt.Println(T.Add)
	fmt.Printf("%T\n", struct {time.Time}.Add)
}

What did you expect to see?

Compile and run okay.

What did you see instead?

Not compile.

$ go run -compiler=gccgo main.go
# command-line-arguments
./main.go:14:15: error: type ‘T’ has no method ‘Add’
  fmt.Println(T.Add)
               ^
./main.go:15:39: error: method expression requires named type or pointer to named type
  fmt.Printf("%T\n", struct {time.Time}.Add)
@dotaheor
Copy link
Author

Another finding:

package main

import (
	"fmt"
	"time"
	"reflect"
)
	
// For gccgo, it is strange that if this type alias declaration
// is removed, then the output is 35, otherwase, it is 0.
type T = struct {
	time.Time
}

func main() {
	var x struct {time.Time}
	var t = reflect.TypeOf(x)
	fmt.Println(t.NumMethod())
}

@andybons
Copy link
Member

@dotaheor can you provide the error that you get when attempting to compile?

/cc @ianlancetaylor @thanm @cherrymui

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 30, 2020
@dotaheor
Copy link
Author

appended.

@gopherbot
Copy link

Change https://golang.org/cl/251168 mentions this issue: test: add test that gccgo failed to compile

@gopherbot
Copy link

Change https://golang.org/cl/251279 mentions this issue: compiler: finalize methods for type aliases of struct types

gopherbot pushed a commit that referenced this issue Aug 28, 2020
For #38125

Change-Id: Id6ef10d74f0f9dbad2851531e0fe019cd145cf7c
Reviewed-on: https://go-review.googlesource.com/c/go/+/251168
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
jpf91 pushed a commit to D-Programming-GDC/gcc that referenced this issue Sep 22, 2020
Previously we would finalize the methods of the alias type itself, but
since its a type alias we really need to finalize the methods of the
aliased type.

Also, handle method expressions of unnamed struct types.

Test case is https://golang.org/cl/251168.

Fixes golang/go#38125

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/251279
@golang golang locked and limited conversation to collaborators Sep 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants