Skip to content

Incorrect use of stale cached code #827

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

Open
antong opened this issue May 29, 2018 · 2 comments
Open

Incorrect use of stale cached code #827

antong opened this issue May 29, 2018 · 2 comments
Labels
bug NeedsFix NeedsHelp Community contributions are welcome for this feature!

Comments

@antong
Copy link

antong commented May 29, 2018

Go 1.10.2 on Windows, GopherJS 1.10-4 (8dffc02)

Compiling using GOOS=linux gopherjs.exe ....

Assume the following package layout:

  • gojscache/gojscache.go : defines type Foo.
  • gojscache/factory/factory.go : constructs a *gojscache.Foo
  • gojscache/use/main.go: imports gojscache and gojscache/factory. Uses gojscache/factory to construct a *gojscache.Foo.

Now, when modifying the top package to add fields to Foo and rebuilding gojscache/use, Gopherjs doesn't rebuild gojscache/factory. This causes the constructor in gojscache/factory to erroneously omit the newly added fields in Foo, leading to errors such as:

..js:13680 Uncaught TypeError: Cannot read property 'constructor' of undefined
    at Object.$packages.reflect.Value.ptr.object (..js:13680)
    at valueInterface (reflect.go:677)
    at Object.$packages.reflect.Value.ptr.Interface (..js:15774)
    at Object.$packages.fmt.pp.ptr.printValue (print.go:699)
    at Object.$packages.fmt.pp.ptr.printValue (print.go:783)
    at Object.$packages.fmt.pp.ptr.printValue (print.go:853)
    at Object.$packages.fmt.pp.ptr.printArg (print.go:689)
    at Object.$packages.fmt.pp.ptr.doPrintln (print.go:1146)
    at Fprintln (print.go:254)
    at Object.Println (..js:17476)
    at main (main.go:11)
    at $init (..js:18826)
    at $goroutine (..js:1471)
    at $runScheduled (..js:1511)
    at $schedule (..js:1527)
    at $go (..js:1503)
    at ..js:18837
    at ..js:18840

This is fixed by #805 .

@antong
Copy link
Author

antong commented Sep 3, 2018

This is still present in GopherJS 1.11-1. To reproduce with the files below, first build foo/use. Then add the member C to foo.Foo. Rebuilding foo/use incorrectly uses the archive foo/factory/factory.a even if its dependency foo is modified (and has a more recent timestamp). Removing said archive corrects the build.

// foo/foo.go
package foo

type Foo struct {
        A int
        B int
        // C int // Uncomment and recompile foo/use to trigger bug
}
// foo/factory/factory.go
package factory

import "foo"

func NewFoo() *foo.Foo {
        return &foo.Foo{}
}
// foo/use/main.go
package main

import (
        "fmt"
        _ "foo" // required to trigger bug
        "foo/factory"
)

func main() {
        x := factory.NewFoo()
        fmt.Println(x)
}

@flimzy
Copy link
Member

flimzy commented Apr 9, 2021

Possibly related to #443, #440

@flimzy flimzy added bug NeedsFix NeedsHelp Community contributions are welcome for this feature! NeedsInvestigation and removed NeedsInvestigation labels Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug NeedsFix NeedsHelp Community contributions are welcome for this feature!
Projects
None yet
Development

No branches or pull requests

2 participants