compiler: add support for the go keyword on interface methods

This is a feature that was long missing, but because of the previous
refactor, it is now trivial to implement.
This commit is contained in:
Ayke van Laethem
2021-10-24 20:58:03 +02:00
committed by Ron Evans
parent a4afc3b4b0
commit 9e1b4de999
6 changed files with 115 additions and 4 deletions
+27
View File
@@ -75,6 +75,8 @@ func main() {
testGoOnBuiltins()
testGoOnInterface(Foo(0))
testCond()
testIssue1790()
@@ -203,6 +205,14 @@ func testCond() {
var once sync.Once
func testGoOnInterface(f Itf) {
go f.Nowait()
time.Sleep(time.Millisecond)
go f.Wait()
time.Sleep(time.Millisecond * 2)
println("done with 'go on interface'")
}
// This tests a fix for issue 1790:
// https://github.com/tinygo-org/tinygo/issues/1790
func testIssue1790() *int {
@@ -210,3 +220,20 @@ func testIssue1790() *int {
i := 0
return &i
}
type Itf interface {
Nowait()
Wait()
}
type Foo string
func (f Foo) Nowait() {
println("called: Foo.Nowait")
}
func (f Foo) Wait() {
println("called: Foo.Wait")
time.Sleep(time.Microsecond)
println(" ...waited")
}
+4
View File
@@ -20,3 +20,7 @@ acquired mutex from goroutine
released mutex from goroutine
re-acquired mutex
done
called: Foo.Nowait
called: Foo.Wait
...waited
done with 'go on interface'