-
Notifications
You must be signed in to change notification settings - Fork 569
Type conversion errors #977
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
Comments
I have been able to reproduce this all the way back to GopherJS 1.12-1, so this does not appear to be caused by using the new GOPHERJS_ROOT configuration, for what that's worth. |
This one has me really stumped. I've attempted to go back to code I knew was working in the past, with an old version of GopherJS, and the problem is still occurring. I would think my local environment was somehow broken, but I first noticed the problem on GitLab-CI, within Docker, so it must be more than that. Can anyone else reproduce this? I'd love a small vote of confidence that I'm not going insane. |
I've tried to reproduce your issue at current master and I noticed an interesting behavior:
Apparently the error occurs when trying to load cached version of Edit: I've encountered a similar error when I implemented gopherjs integration with bazel, although in a more bizarre form, it claimed unable to convert time.Time to time.Time (or any other type from standard library) :) At the time I blamed it onto a lame way I handled building standard library, but perhaps it has a similar root. I'll try to investigate that bug again when I have a bit of time and post if I find anything useful here. |
Thank you for taking the time! I've noticed a number of other gopherjs caching bugs, and am in the habit of clearing the cache before each build. That doesn't seem to be enough to make this work in my larger program (perhaps because the same import is included more than once, so hitting the cache is inevitable?) |
My gut feeling is that the bug lays at the border between how gopherjs caches intermediate build results and how go/types checks for type equality. I suspect that go/types relies on pointer equality somewhere for type equality checks, but that gets disturbed by serializing/deserializing a library archive. I haven't verified this, though, so take it with a grain of salt. |
I spent a bunch of time with the debugger and tracked down the error source. How the error happens?The failing check is test whether time.Time is assignable to types.Time. The reason why first and second passes behave differently is that "underlying type" for time.Time and types.Time looks different between runs. The first time the underlying type refers to the struct in with a list of fields, and for those fields
The second time, there is a subtle difference in that the fields are referencing
The type in both cases structurally the same, but the subtle difference (at least as I interpret it) is that in the first case fields say "I was originally defined in Code relevant to this logic is located in https://github.com/golang/go/blob/master/src/go/types/conversions.go if anyone's interested. What causes the error to happen?Long story short, the problem seems to be rooted in There seems to be a complimentary bug when reading field information, where it just assumes the surrounding package: https://github.com/golang/tools/blob/0f592d2728bb767204b019bf926fbcd791267115/go/internal/gcimporter/iimport.go#L542. Unfortunately that means that even updating the write part to use How to fix the problem?Unfortunately, I've no idea. I don't think GopherJS is doing anything wrong here, the bug seems to be mostly localized to the |
/cc @dmitshur in case he knows something useful about |
I've run into an unusual problem. In my real code, the result is inconsistent:
If I run my code once, it succeeds, but the second run, with no manual changes, produces the error:
Running
go mod vendor
somehow "resets" the state, so that the next run will work again, but after one success, it's broken again.Strange.
I have been able to reproduce a minimal test case, but it consistently exhibits the failure, so I'm not sure what's different. Full code is here: https://github.com/flimzy/timeconvertiontest
Summary:
Define a custom type
Time
in an imported package:Then try to convert from
time.Time
to the custom type:When I build the code in the linked repository, using both Go (1.14) and GopherJS (1.12):
The text was updated successfully, but these errors were encountered: