aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorPhil Kedy <[email protected]>2022-07-28 10:34:27 -0400
committerRon Evans <[email protected]>2022-08-01 10:53:48 +0200
commit05cdde162c2a983fa5cc504cbb6bf9dedfda81ab (patch)
tree40d2f82574927b09bb68f97554fc095015a8fefe /testdata
parent25c8d3ec3a80fb069fcd96169ab0fb60902cff22 (diff)
downloadtinygo-05cdde162c2a983fa5cc504cbb6bf9dedfda81ab.tar.gz
tinygo-05cdde162c2a983fa5cc504cbb6bf9dedfda81ab.zip
Set internal linkage and keeping default visibility for anonymous functions
Diffstat (limited to 'testdata')
-rw-r--r--testdata/generics.go8
-rw-r--r--testdata/generics.txt4
-rw-r--r--testdata/generics/testa/testa.go20
-rw-r--r--testdata/generics/testb/testb.go20
-rw-r--r--testdata/generics/value/value.go53
5 files changed, 105 insertions, 0 deletions
diff --git a/testdata/generics.go b/testdata/generics.go
index 2286bb0d5..c2877dfd8 100644
--- a/testdata/generics.go
+++ b/testdata/generics.go
@@ -1,11 +1,19 @@
package main
+import (
+ "github.com/tinygo-org/tinygo/testdata/generics/testa"
+ "github.com/tinygo-org/tinygo/testdata/generics/testb"
+)
+
func main() {
println("add:", Add(3, 5))
println("add:", Add(int8(3), 5))
var c C[int]
c.F() // issue 2951
+
+ testa.Test()
+ testb.Test()
}
type Integer interface {
diff --git a/testdata/generics.txt b/testdata/generics.txt
index 073514b9d..0fbe45fd4 100644
--- a/testdata/generics.txt
+++ b/testdata/generics.txt
@@ -1,2 +1,6 @@
add: 8
add: 8
+value: 101
+value: 101
+value: 501
+value: 501
diff --git a/testdata/generics/testa/testa.go b/testdata/generics/testa/testa.go
new file mode 100644
index 000000000..87cca737a
--- /dev/null
+++ b/testdata/generics/testa/testa.go
@@ -0,0 +1,20 @@
+package testa
+
+import (
+ "github.com/tinygo-org/tinygo/testdata/generics/value"
+)
+
+func Test() {
+ v := value.New(1)
+ vm := value.Map(v, Plus100)
+ vm.Get(callback, callback)
+}
+
+func callback(v int) {
+ println("value:", v)
+}
+
+// Plus100 is a `Transform` that adds 100 to `value`.
+func Plus100(value int) int {
+ return value + 100
+}
diff --git a/testdata/generics/testb/testb.go b/testdata/generics/testb/testb.go
new file mode 100644
index 000000000..263c7ce39
--- /dev/null
+++ b/testdata/generics/testb/testb.go
@@ -0,0 +1,20 @@
+package testb
+
+import (
+ "github.com/tinygo-org/tinygo/testdata/generics/value"
+)
+
+func Test() {
+ v := value.New(1)
+ vm := value.Map(v, Plus500)
+ vm.Get(callback, callback)
+}
+
+func callback(v int) {
+ println("value:", v)
+}
+
+// Plus500 is a `Transform` that adds 500 to `value`.
+func Plus500(value int) int {
+ return value + 500
+}
diff --git a/testdata/generics/value/value.go b/testdata/generics/value/value.go
new file mode 100644
index 000000000..5348f1848
--- /dev/null
+++ b/testdata/generics/value/value.go
@@ -0,0 +1,53 @@
+package value
+
+type (
+ Value[T any] interface {
+ Get(Callback[T], Callback[T])
+ }
+
+ Callback[T any] func(T)
+
+ Transform[S any, D any] func(S) D
+)
+
+func New[T any](v T) Value[T] {
+ return &value[T]{
+ v: v,
+ }
+}
+
+type value[T any] struct {
+ v T
+}
+
+func (v *value[T]) Get(fn1, fn2 Callback[T]) {
+ // For example purposes.
+ // Normally would be asynchronous callback.
+ fn1(v.v)
+ fn2(v.v)
+}
+
+func Map[S, D any](v Value[S], tx Transform[S, D]) Value[D] {
+ return &mapper[S, D]{
+ v: v,
+ tx: tx,
+ }
+}
+
+type mapper[S, D any] struct {
+ v Value[S]
+ tx Transform[S, D]
+}
+
+func (m *mapper[S, D]) Get(fn1, fn2 Callback[D]) {
+ // two callbacks are passed to generate more than
+ // one anonymous function symbol name.
+ m.v.Get(func(v S) {
+ // anonymous function inside of anonymous function.
+ func() {
+ fn1(m.tx(v))
+ }()
+ }, func(v S) {
+ fn2(m.tx(v))
+ })
+}