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

cmd/gc: inlining of functions with local variables is broken with shadowing. #4326

Closed
remyoudompheng opened this issue Nov 1, 2012 · 3 comments
Milestone

Comments

@remyoudompheng
Copy link
Contributor

1. What is a short input program that triggers the error?

Here are two examples:

$ cat p1.go
package p1

type O map[string]map[string]string

func (opts O) RemoveOption(sect, opt string) bool {
    if _, ok := opts[sect]; !ok {
        return false
    }
    _, ok := opts[sect][opt]
    delete(opts[sect], opt)
    return ok
}
$ cat p2.go
package p2

import "./p1"

func NewO() p1.O { return nil }
$ cat main.go
package main

import "./p2"

func main() {
    p2.NewO().RemoveOption("hello", "world")
}

$ cat q1.go
package q1

func Deref(typ interface{}) interface{} {
      if typ, ok := typ.(*int); ok {
            return *typ
      }
      return typ
}
$ cat q2.go
package main

import "./q1"

func main() {
      x := 1
      y := q1.Deref(&x)
      if y != 1 {
            panic("y != 1")
      }
}

2. What is the full compiler output?

$ go tool 8g -I. p1.go
$ go tool 8g -I. p2.go
$ go tool 8g -I. main.go
main.go:3: p1.ok redeclared in this block
    previous declaration at main.go:3
go tool 8g: exit status 1

$ go tool 8g -I. q1.go
$ go tool 8g -I. q2.go
q2.go:3: invalid type assertion: q1.typ.(*int) (non-interface type *int on left)
q2.go:7: tempname called with nil type
q2.go:7: internal compiler error: typename <T>
go tool 8g: exit status 1

3. What version of the compiler are you using?  (Run it with the -V flag.)

8g version devel +5bc48b616305 Thu Nov 01 13:04:08 2012 +1100

Attachments:

  1. inlining.tar.gz (530 bytes)
@dvyukov
Copy link
Member

dvyukov commented Nov 6, 2012

Comment 1:

Just debugged the same issue.
Note how {} disappear around  {  var @"".ok bool; _, @"".ok = @"".s.@"".lo.(@"".Int); if
@"".ok { return true }} after inlining:
//pkg1
        func (@"".s *@"".Interval "esc:0x0") IsInt() (? bool) { if @"".s == nil { return false }; {  var @"".ok bool; _, @"".ok = @"".s.@"".lo.(@"".Int); if @"".ok { return true }}; {  var @"".ok bool; _, @"".ok = @"".s.@"".hi.(@"".Int); if @"".ok { return true }}; return false }
//pkg2
        func (@"bugtest/pkg".s *@"bugtest/pkg".Interval "esc:0x0") IsInt2() (? bool) { if @"bugtest/pkg".s == nil { return false }; var @"bugtest/pkg".ok bool; ; _, @"bugtest/pkg".ok = @"bugtest/pkg".s.@"bugtest/pkg".lo.(@"bugtest/pkg".Int); if @"bugtest/pkg".ok { return true }; var @"bugtest/pkg".ok bool; ; _, @"bugtest/pkg".ok = @"bugtest/pkg".s.@"bugtest/pkg".hi.(@"bugtest/pkg".Int); if @"bugtest/pkg".ok { return true }; return false }
The error message is:
main.go:4: pkg.ok redeclared in this block

Labels changed: added compilerbug.

@rsc
Copy link
Contributor

rsc commented Nov 6, 2012

Comment 2:

I'll try to take a look at this today.

@rsc
Copy link
Contributor

rsc commented Nov 7, 2012

Comment 3:

This issue was closed by revision cb856ad.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 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

4 participants