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: compiler does not detect illegal assignment to a private struct member #6832

Closed
davecheney opened this issue Nov 25, 2013 · 8 comments

Comments

@davecheney
Copy link
Contributor

What steps will reproduce the problem?

lucky(~/src) % cat a/a.go 
package a

type MyError struct {
        error
}
lucky(~/src) % cat b/b.go
package b

import "errors"
import "a"

func F() error {
        return &a.MyError{errors.New("plop")}
}

What is the expected output? What do you see instead?

Expected:

lucky(~/src) % go build -compiler gc b
# b
b/b.go:7: implicit assignment of unexported field 'error' in a.MyError literal

Got:

lucky(~/src) % go build -compiler gccgo b
lucky(~/src) % echo $?
0

Please use labels and text to provide additional information.
@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 1:

Labels changed: added go1.3maybe.

@gopherbot
Copy link
Contributor

Comment 2 by r@rcrowley.org:

This feature of gc was actually introduced in 1.2, as well.  We use a struct defined
pretty much like Dave's a.MyError above which works just fine in Go 1.1.2 but began
failing as Dave shows above with Go 1.2.
Was there a change that made such assignments illegal?  By the lexical rules for
exported/unexported the 1.2 behavior seems right but I've always seen error (and string,
map, append, copy, len, cap, new, make, etc.) as special and above that rule.

@davecheney
Copy link
Contributor Author

Comment 3:

> Was there a change that made such assignments illegal?  By the lexical rules for
exported/unexported the 1.2 behavior seems right but I've always seen error (and string,
map, append, copy, len, cap, new, make, etc.) as special and above that rule.
Nope, these assignments have always been illegal, but this is enforced at compile time,
not runtime so if the compiler didn't stop them, nothing will.

@wadey
Copy link
Contributor

wadey commented Dec 3, 2013

Comment 4:

I think this change to "fix" the enforcement in go1.2 should have been documented in the
release notes, as it did break existing programs that worked in go1.1.2. Was this just
overlooked?

@ianlancetaylor
Copy link
Contributor

Comment 5:

>I think this change to "fix" the enforcement in go1.2 should have been documented in
the release notes, as it did break existing programs that worked in go1.1.2. Was this
just overlooked?
Yes, probably.  You may want to open a separate doc issue for that.

@ianlancetaylor
Copy link
Contributor

Comment 6:

Gccgo will not be part of the Go 1.3 release.

Labels changed: removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added repo-gccgo.

@paranoiacblack
Copy link
Contributor

Fixed in gcc.gnu.org/r219313.

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Jan 7, 2015
literals.

Fixes golang/go#6832.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219313 138bc75d-0d04-0410-961f-82ee72b054a4
paranoiacblack pushed a commit to golang/gofrontend that referenced this issue Jan 27, 2015
literals.

Fixes golang/go#6832.

LGTM=iant
R=iant
CC=gofrontend-dev
https://codereview.appspot.com/191500043

Committer: Ian Lance Taylor <iant@golang.org>
paranoiacblack pushed a commit to golang/gofrontend that referenced this issue Jun 2, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
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

6 participants