Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Second enclosed function can't access pointer #402

Open
@flimzy

Description

@flimzy

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions