mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
compiler: add support for running a builtin in a goroutine
Not sure why you would ever do this, but it appears to be allowed by the Go specification and previously TinyGo would crash with an unhelpful error message when you would do this. I don't see any practical use of it. The implementation simply runs the builtin directly.
This commit is contained in:
committed by
Ron Evans
parent
87c2ccb0b9
commit
ec325c0643
Vendored
+27
@@ -73,6 +73,8 @@ func main() {
|
||||
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
|
||||
testGoOnBuiltins()
|
||||
|
||||
testCond()
|
||||
}
|
||||
|
||||
@@ -131,6 +133,31 @@ type simpleFunc func()
|
||||
func emptyFunc() {
|
||||
}
|
||||
|
||||
func testGoOnBuiltins() {
|
||||
// Test copy builtin (there is no non-racy practical use of this).
|
||||
go copy(make([]int, 8), []int{2, 5, 8, 4})
|
||||
|
||||
// Test recover builtin (no-op).
|
||||
go recover()
|
||||
|
||||
// Test close builtin.
|
||||
ch := make(chan int)
|
||||
go close(ch)
|
||||
n, ok := <-ch
|
||||
if n != 0 || ok != false {
|
||||
println("error: expected closed channel to return 0, false")
|
||||
}
|
||||
|
||||
// Test delete builtin.
|
||||
m := map[string]int{"foo": 3}
|
||||
go delete(m, "foo")
|
||||
time.Sleep(time.Millisecond)
|
||||
v, ok := m["foo"]
|
||||
if v != 0 || ok != false {
|
||||
println("error: expected deleted map entry to be 0, false")
|
||||
}
|
||||
}
|
||||
|
||||
func testCond() {
|
||||
var cond runtime.Cond
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user