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

Pointer type is not converted correctly when assigned to a struct literal #1240

Open
nevkontakte opened this issue Nov 1, 2023 · 0 comments

Comments

@nevkontakte
Copy link
Member

Example:

package main

import (
	"fmt"
	"reflect"
)

type strPtr *string

func main() {
	var s string = "abc"

	var s1 *string = &s
	var s2 strPtr = &s
	fmt.Println(reflect.TypeOf(s1), reflect.TypeOf(s2))

	v := struct {
		s1 *string
		s2 strPtr
	}{
		s1: &s,
		s2: &s,
	}
	fmt.Println(reflect.TypeOf(v.s1), reflect.TypeOf(v.s2))
}

Expected output:

*string main.strPtr
*string main.strPtr

Actual output:

*string main.strPtr
*string *string

Proximate cause:

Composite literal compilation calls fc.translateImplicitConversionWithCloning() (example), which handles pointer type conversion as a no-op, which is probably incorrect.

@nevkontakte nevkontakte added the bug label Nov 1, 2023
@nevkontakte nevkontakte added this to the Go spec compliance milestone Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant