Second enclosed function can't access pointer
Consider the following code:
package main
import "fmt"
func main() {
var x int
go func() {
fmt.Println(&x)
}()
go func() {
fmt.Println(&x)
}()
}
The output of 'gopherjs run' is:
$ gopherjs run x.go
gopherjs: Source maps disabled. Use Node.js 4.x with source-map-support module for nice stack traces.
0x1
/home/jonhall/go/src/github.com/flimzy/x/x.go.705403117:1472
throw err;
^
ReferenceError: x$24ptr is not defined
at $b (/home/jonhall/go/src/github.com/flimzy/x/x.go.705403117:15912:37)
at $goroutine (/home/jonhall/go/src/github.com/flimzy/x/x.go.705403117:1463:19)
at $runScheduled [as _onTimeout] (/home/jonhall/go/src/github.com/flimzy/x/x.go.705403117:1504:7)
at Timer.listOnTimeout (timers.js:92:15)
When I look at the compiled JS output, I see the apparent problem (with line numbers):
15902 $go((function $b() {
15903 var $ptr, _r, x$24ptr, $s, $r;
15909 $go((function $b() {
15910 var $ptr, _r, $s, $r;
I can reproduce on gopherjs playground:
http://www.gopherjs.org/playground/#/QlMAXNNSG9
Interestingly, it doesn't happen if you add something like fmt.Println() at the end:
http://www.gopherjs.org/playground/#/1Ec8axHq-N
I think I ran into the same issue using GopherJS 1.8-1. The stack trace is:
Uncaught ReferenceError: timedOut$24ptr is not defined
at setRequestCancel (ui.js:98548)
at send (client.go:247)
at Object.$packages.net/http.Client.ptr.send (client.go:173)
at Object.$packages.net/http.Client.ptr.Do (client.go:595)
at Object.$b [as Fn] (handlers.go:103)
at Object.$packages.github.com/aws/aws-sdk-go/aws/request.HandlerList.ptr.Run (handlers.go:136)
at Object.$packages.github.com/aws/aws-sdk-go/aws/request.Request.ptr.Send (request.go:374)
at Object.$packages.github.com/aws/aws-sdk-go/aws/ec2metadata.EC2Metadata.ptr.GetMetadata (api.go:28)
at requestCredList (ec2_role_provider.go:133)
at Object.$packages.github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds.EC2RoleProvider.ptr.Retrieve (ec2_role_provider.go:89)
at Object.$packages.github.com/aws/aws-sdk-go/aws/credentials.ChainProvider.ptr.Retrieve (chain_provider.go:75)
at Object.$packages.github.com/aws/aws-sdk-go/aws/credentials.Credentials.ptr.Get (credentials.go:185)
at Object.$packages.github.com/aws/aws-sdk-go/aws/signer/v4.Signer.ptr.signWithBody (v4.go:332)
at signSDKRequestWithCurrTime (v4.go:449)
at Object.SignSDKRequest [as Fn] (v4.go:410)
at Object.$packages.github.com/aws/aws-sdk-go/aws/request.HandlerList.ptr.Run (handlers.go:136)
at Object.$packages.github.com/aws/aws-sdk-go/aws/request.Request.ptr.Sign (request.go:236)
at Object.$packages.github.com/aws/aws-sdk-go/aws/request.Request.ptr.Send (request.go:367)
at Object.$packages.github.com/aws/aws-sdk-go/service/cognitoidentityprovider.CognitoIdentityProvider.ptr.InitiateAuth (api.go:4356)
at Object.$b [as Listener] (main.go:233)
at $b (dom.go:206)
at HTMLButtonElement.v.$externalizeWrapper (ui.js:1870)
where line 98548 corresponds to line 71 in this gist: https://gist.github.com/jancona/441352b86fcd8553fd445adffb2f0a5f
Because this happens inside library code, I don't think there's an easy workaround.
I can still reproduce this in the current version of the playground.