public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/100388] New: import seems to define identifiers in package block not file block
@ 2021-05-02 20:16 ben.hutchings at essensium dot com
  0 siblings, 0 replies; only message in thread
From: ben.hutchings at essensium dot com @ 2021-05-02 20:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100388

            Bug ID: 100388
           Summary: import seems to define identifiers in package block
                    not file block
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: ben.hutchings at essensium dot com
                CC: cmang at google dot com
  Target Milestone: ---

Given a package made of these two files:

$ cat a.go
package main

import (
        copy "golang.org/x/sys/unix"
)

func Getuid() int {
        return copy.Getuid()
}
$ cat b.go
package main

func main() {
        foo := make([]string, 1)
        bar := make([]string, 1)
        copy(bar, foo)
}

gccgo seems to treat the imported "copy" as defined at package scope, shadowing
the global "copy":

$ go build .
# _/home/bwh/tmp/gotest
./b.go:6:2: error: ‘copy’ defined as both imported name and global name
    6 |  copy(bar, foo)
      |  ^
./a.go:4:2: note: ‘copy’ imported here
    4 |  copy "golang.org/x/sys/unix"
      |  ^

I'm seeing this with the Debian package of gccgo, version 10.2.1-6.

gc (again from a Debian package, version 1.15.9-1) does not report an error.

The Go Programming Language spec says that import declares names in the "file
block" which seems to mean it should not affect any other source file. But I am
a Go novice, so I might be misinterpreting this.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-02 20:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-02 20:16 [Bug go/100388] New: import seems to define identifiers in package block not file block ben.hutchings at essensium dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).