gopherjs / gopherjs/gopherjs

reflect.go's Select on Array-type Channel "$set is not a function"

Open
#773 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug NeedsFix NeedsInvestigation
Dominant language
Go
Stars
13.2k
Forks
573
PR merge metrics
No merged PRs in 30d

Description

package main

import "reflect"

func main() {
	ch := make(chan [2]string)

	go func() { ch <- [2]string{"Hello", "World"} }()

	rch := reflect.ValueOf(ch)
	chosen, rv, _ := reflect.Select([]reflect.SelectCase{{Dir: reflect.SelectRecv, Chan: rch}})
	switch chosen {
	case 0:
		sl := rv.Interface().([2]string)
		println(sl[0], sl[1])
	}
}

JavaScript Error:

TypeError: (intermediate value).val.$set is not a function

Version: GopherJS 1.8-2
Run: "build" (not minified)
Machine: Windows 10 (64-bit)
Browser: Firefox 58.0.2 (64-bit)

Full JavaScript stack trace:

TypeError: (intermediate value).val.$set is not a function reflect.go:1351:3
rselect reflect.go:1351:3
Select value.go:2016:2
main test.go:11:2
$init file:///C:/Users/amatu/go/src/test/test.js:7826:65
fun file:///C:/Users/amatu/go/src/test/test.js:1473:35
$goroutine file:///C:/Users/amatu/go/src/test/test.js:1471:15
$runScheduled file:///C:/Users/amatu/go/src/test/test.js:1511:7
$schedule file:///C:/Users/amatu/go/src/test/test.js:1527:5
$go file:///C:/Users/amatu/go/src/test/test.js:1503:3
file:///C:/Users/amatu/go/src/test/test.js:7837:1
file:///C:/Users/amatu/go/src/test/test.js:2:2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided program, then inspect reflect.go:1351 and the Select path in value.go:2016 where the stack trace points. Compare array-channel handling with other reflected channel values; done means reflect.Select receives the [2]string value and the program prints Hello World without a JavaScript exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.