Skip to content
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

v2 does not compile with go1.14 #74

Closed
inliquid opened this issue Mar 7, 2020 · 2 comments
Closed

v2 does not compile with go1.14 #74

inliquid opened this issue Mar 7, 2020 · 2 comments

Comments

@inliquid
Copy link
Contributor

inliquid commented Mar 7, 2020

When building a v2-based program with go1.14:

# honnef.co/go/js/dom/v2
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:121:7: invalid operation: o == js.Null() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:121:25: invalid operation: o == js.Undefined() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:144:27: invalid operation: n != js.Undefined() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:160:26: invalid operation: o.Get("constructor") == js.Global().Get("Array") (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:218:2: cannot switch on elementConstructor(o) (type js.Value) (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:227:2: cannot switch on elementConstructor(o) (type js.Value) (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:235:7: invalid operation: o == js.Null() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:235:25: invalid operation: o == js.Undefined() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:238:2: cannot switch on elementConstructor(o) (type js.Value) (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:248:7: invalid operation: o == js.Null() (struct containing [0]func() cannot be compared)
..\..\..\..\..\..\pkg\mod\honnef.co\go\js\dom\v2@v2.0.0-20190526011328-ebc4cf92d81f\dom.go:248:7: too many errors
@dmitshur
Copy link
Collaborator

dmitshur commented Mar 7, 2020

Thanks for reporting.

This is due to syscall/js API changes in Go 1.14 (documented here). In order to fix this issue and preserve compatibility with 1.13, we must use build constraints. Either by making a copy of the entire dom.go file, or by creating relevant helpers.

@dmitshur
Copy link
Collaborator

dmitshur commented Apr 18, 2020

/cc @neelance @cherrymui FYI, the Go 1.14 change to require use of Equal method to compare js.Value values has a noticeable effect on on large switches. E.g.:

switch c := o.Get("constructor"); c {
case js.Global().Get("AnimationEvent"):
	return &AnimationEvent{ev}
case js.Global().Get("AudioProcessingEvent"):
	return &AudioProcessingEvent{ev}
case js.Global().Get("BeforeInputEvent"):
	return &BeforeInputEvent{ev}
case js.Global().Get("BeforeUnloadEvent"):
	return &BeforeUnloadEvent{ev}
case js.Global().Get("BlobEvent"):
	return &BlobEvent{ev}
case js.Global().Get("ClipboardEvent"):
	return &ClipboardEvent{ev}
case js.Global().Get("CloseEvent"):
	return &CloseEvent{BasicEvent: ev}
case js.Global().Get("CompositionEvent"):
	return &CompositionEvent{ev}
case js.Global().Get("CSSFontFaceLoadEvent"):
	return &CSSFontFaceLoadEvent{ev}
case js.Global().Get("CustomEvent"):
	return &CustomEvent{ev}
...

Needs to be rewritten into something like:

switch c := o.Get("constructor"); {
case c.Equal(js.Global().Get("AnimationEvent"):
	return &AnimationEvent{ev}
case c.Equal(js.Global().Get("AudioProcessingEvent")):
	return &AudioProcessingEvent{ev}
case c.Equal(js.Global().Get("BeforeInputEvent")):
	return &BeforeInputEvent{ev}
case c.Equal(js.Global().Get("BeforeUnloadEvent")):
	return &BeforeUnloadEvent{ev}
case c.Equal(js.Global().Get("BlobEvent")):
	return &BlobEvent{ev}
case c.Equal(js.Global().Get("ClipboardEvent")):
	return &ClipboardEvent{ev}
case c.Equal(js.Global().Get("CloseEvent")):
	return &CloseEvent{BasicEvent: ev}
case c.Equal(js.Global().Get("CompositionEvent")):
	return &CompositionEvent{ev}
case c.Equal(js.Global().Get("CSSFontFaceLoadEvent")):
	return &CSSFontFaceLoadEvent{ev}
case c.Equal(js.Global().Get("CustomEvent")):
	return &CustomEvent{ev}
...

Just sharing this observation.

dmitshur added a commit that referenced this issue May 4, 2020
The syscall/js API has changed in Go 1.14 as described
at https://golang.org/doc/go1.14#wasm.
Start using it, but keep compatibility for Go 1.13 and older
by making copies of .go files and using build constraints.

Fixes #74.

Co-authored-by: Dmitri Shuralyov <dmitri@shuralyov.com>
GitHub-Pull-Request: #75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants