You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ go version
go version go1.12.2 gccgo (GCC) 10.0.0 20190703 (experimental) linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
linux/amd64
What did you do?
Compile these packages (first "a" and then "b"):
Package "a":
package a
import "os"
func M() string {
if s := os.Getenv("Fred"); s != "" {
return s
}
if s := os.Getenv("Joe"); s != "" {
return s
}
return string("Alex")
}
Package "b":
package b
import "a"
func B() string {
return a.M()
}
What did you expect to see?
Clean build
What did you see instead?
Compile failure:
$ go build b
# b
/ssd2/go1/src/a/a.go:9: error: redefinition of ‘s’
/ssd2/go1/src/a/a.go:6: note: previous definition of ‘s’ was here
Looks as though we are treating "s" as a duplicate while importing "a.M'. Here is the export data:
func M () ($ret0 <type -16>) <inl:379>
// /ssd2/go1/src/a/a.go:5
{ //6
var s <type -16> = <p1>Getenv("Fred") //6
if (s != "") { //6
{ //7
$ret0 = s //7
return //7
} //0
} //6
} //8
{ //9
var s <type -16> = <p1>Getenv("Joe") //9
if (s != "") { //9
{ //10
$ret0 = s //10
return //10
} //0
} //9
} //11
{ //12
$ret0 = $convert(<type -16>, "Alex") //12
return //12
} //0
I think the problem area is in Variable_declaration_statement::do_import, statements.cc line 473:
Named_object* no = ifb->block()->bindings()->add_variable(id, NULL, var);
return Statement::make_variable_declaration(no);
This is using a single block associated with the Import_function_body object, when in fact I think what we want is to keep a stack of the current block nesting. I will look into a fix.
The text was updated successfully, but these errors were encountered:
This patch fixes a buglet in the function body importer. Add hooks for
keeping a stack of blocks corresponding to the block nesting in the
imported function. This ensures that local variables and temps wind up
correctly scoped and don't introduce collisions.
New test case for this problem in CL 186717.
Fixesgolang/go#33158.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/186757
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@273577 138bc75d-0d04-0410-961f-82ee72b054a4
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
Compile these packages (first "a" and then "b"):
Package "a":
Package "b":
What did you expect to see?
Clean build
What did you see instead?
Compile failure:
Looks as though we are treating "s" as a duplicate while importing "a.M'. Here is the export data:
I think the problem area is in Variable_declaration_statement::do_import, statements.cc line 473:
This is using a single block associated with the Import_function_body object, when in fact I think what we want is to keep a stack of the current block nesting. I will look into a fix.
The text was updated successfully, but these errors were encountered: