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

reflect: regression in Type.ConvertibleTo #17952

Closed
dsnet opened this issue Nov 16, 2016 · 2 comments
Closed

reflect: regression in Type.ConvertibleTo #17952

dsnet opened this issue Nov 16, 2016 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Nov 16, 2016

8d0c105 caused a regression in functionality of ConvertibleTo.

The following test passes on Go 1.6 and 1.7, but fails on tip:

type timeTime time.Time

func Test(t *testing.T) {
	t1 := reflect.TypeOf((*time.Time)(nil))
	t2 := reflect.TypeOf((*timeTime)(nil))
	if !t1.ConvertibleTo(t2) || !t2.ConvertibleTo(t1) {
		t.Error("pointers not convertible")
	}

	t1 = reflect.TypeOf(time.Time{})
	t2 = reflect.TypeOf(timeTime{})
	if !t1.ConvertibleTo(t2) || !t2.ConvertibleTo(t1) {
		t.Error("values not convertible")
	}
}

/cc @rsc, @crawshaw, @ianlancetaylor

@dsnet dsnet added this to the Go1.8 milestone Nov 16, 2016
@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 16, 2016
@ianlancetaylor
Copy link
Contributor

The problem is that for a definition like type timeTime time.Time the pkgPath of the struct is the package in which it is defined (in this case, main) and we use that pkgPath for the pkgPath of all the fields. But of course the fields are defined in package time.

Similarly, printing Field(i).PkgPath of reflect.TypeOf(timeTime) also prints the wrong value.

dnameField in cmd/compile/internal/gc/reflect.go assumes that it never needs to set the pkgPath of a field, but as far as I can tell that simply isn't true.

@gopherbot
Copy link

CL https://golang.org/cl/33333 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 17, 2017
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

4 participants