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

Compile error when imported package method returns anonymous struct with embedded field #6773

Closed
gopherbot opened this issue Nov 15, 2013 · 6 comments

Comments

@gopherbot
Copy link

by vincent@callanan.ie:

What steps will reproduce the problem?

See my post on forum.
Please read down to end as my initial post was confusing.

https://groups.google.com/forum/#!topic/golang-nuts/8hDGgu31iHE

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Windows 7 Pro SP1 64-bit

Which version are you using?
go1.1.2 windows/amd64

Please provide any additional information below.

Ian was unable to reproduce problem.
Is this perhaps a platform-specific issue (Windows/AMD64)?
@ianlancetaylor
Copy link
Contributor

Comment 1:

Please attach a standalone test case to this bug report, rather than referring to the
somewhat confusing mailing list thread.  Thanks.

@gopherbot
Copy link
Author

Comment 2 by vincent@callanan.ie:

Just tested on 1.2rc4 (Windows/AMD64).
Bug is not present.

@gopherbot
Copy link
Author

Comment 3 by vincent@callanan.ie:

Ok, while bug is not present in 1.2rc4,
You may still need to patch 1.1.2
So here is relevant part of thread:
---------------------------------------------
This version works....
package pkgA
type item struct {
    val int
}
type ReadOnlyItem struct {
    *item
}
func (this *item) Val() int {
    return this.val
}
func GetItem() ReadOnlyItem {
    return ReadOnlyItem{&item{1234}}
}
-----------------------------------------------
package main
import (
    "....../pkgA"
    "fmt"
)
func main() {
    fmt.Println(pkgA.GetItem().Val())
}
------------------------------------------
But when I replace func GetItem() in pkgA with
func GetItem() struct{ *item } {
    return struct{ *item }{&item{1234}}
}
pkgA compiles ok, but I get the following compile error in package main at the import
"pkgA" line:
unknown struct {} field 'pkgA.item' in struct literal

@remyoudompheng
Copy link
Contributor

Comment 4:

This is issue #5910

@gopherbot
Copy link
Author

Comment 5 by vincent@callanan.ie:

Thanks,
I saw that bug but thought it had something to do with channels.
Out of curiosity, there appears to be some trepidation about this whole area
i.e. anonymous structs/embedded fields/inlining.
Can we assume that the relevant code is "reasonably clean" at this point (1.2rc4)?

@ianlancetaylor
Copy link
Contributor

Comment 6:

As far as we know the tools work correctly.  Of course bugs are always possible.  I
don't see any trepidation myself.

Status changed to Duplicate.

Merged into issue #5910.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants