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

Skip to content

Type conversion errors #977

Closed
Closed
@flimzy

Description

@flimzy

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:

$ gopherjs run ./foo/foo.go
gopherjs: Source maps disabled. Install source-map-support module for nice stack traces. See https://github.com/gopherjs/gopherjs#gopherjs-run-gopherjs-test.
2020-04-10 13:42:11.405 +0200 Central European Summer Time m=+0.083000001
2020-04-10 13:42:11
{13806968577655557952 83000001 0x1}
jonhall@hyaline:~/go/src/gitlab.com/FlashbackSRS/priv/fbrender$ gopherjs run ./foo/foo.go
foo/foo.go:14:14: cannot convert x (variable of type time.Time) to fb.Due

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:

package foo

import "time"

type Time time.Time

Then try to convert from time.Time to the custom type:

package main

import (
    "time"
    "foo"
)

func main() {
    _ = foo.Time(time.Now())
}

When I build the code in the linked repository, using both Go (1.14) and GopherJS (1.12):

$ go build main.go
$ gopherjs build main.go
main.go:10:17: cannot convert time.Now() (value of type time.Time) to types.Time

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions