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: reflect.Type.Method doesn't correctly report variadic function #41737

Closed
ianlancetaylor opened this issue Oct 1, 2020 · 4 comments
Closed
Assignees
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 1, 2020

When the following program is run by the gc compiler it prints

in: 3; out: 0; variadic: true

When run by gccgo it prints

in: 3; out: 0; variadic: false

This is a bug somewhere in the gofrontend code.

package main

import (
	"fmt"
	"reflect"
)

type E struct{}

func (E) M(x string, xs ...int) {}

func main() {
	t := reflect.TypeOf(E{})
	for i := 0; i < t.NumMethod(); i++ {
		tm := t.Method(i).Type
		fmt.Printf("in: %d; out: %d; variadic: %t\n", tm.NumIn(), tm.NumOut(), tm.IsVariadic())
	}
}

CC @thanm @cherrymui @advancedwebdeveloper

@ianlancetaylor
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Oct 1, 2020

This was distilled from antonmedv/expr#139.

@ianlancetaylor ianlancetaylor self-assigned this Oct 1, 2020
@ianlancetaylor
Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Oct 1, 2020

It looks like a pretty simple bug. Kind of astonishing that it hasn't been noticed until now.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 1, 2020

Change https://golang.org/cl/258819 mentions this issue: reflect: add test for variadic reflect.Type.Method

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 1, 2020

Change https://golang.org/cl/258977 mentions this issue: compiler: set varargs correctly for type of method expression

gopherbot pushed a commit that referenced this issue Oct 1, 2020
For #41737

Change-Id: Id065880dd7da54dec1b45662c202aeb7f8397c60
Reviewed-on: https://go-review.googlesource.com/c/go/+/258819
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.