From 85d2eadcf2715a1230e393ca4cd65ad328f76966 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Mon, 12 Aug 2024 16:01:55 -0400 Subject: [PATCH] test: add test case for wasmexport parameter types For #65199. Change-Id: Iecd11281706201a655b51583a08318b5ffd8ab04 Reviewed-on: https://go-review.googlesource.com/c/go/+/604975 Reviewed-by: Johan Brandhorst-Satzkorn LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- test/wasmexport2.go | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/wasmexport2.go diff --git a/test/wasmexport2.go b/test/wasmexport2.go new file mode 100644 index 0000000000..c7c0fa2ec8 --- /dev/null +++ b/test/wasmexport2.go @@ -0,0 +1,58 @@ +// errorcheck + +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Verify that wasmexport supports allowed types and rejects +// unallowed types. + +//go:build wasm + +package p + +import "unsafe" + +//go:wasmexport good1 +func good1(int32, uint32, int64, uint64, float32, float64, unsafe.Pointer) {} // allowed types + +type MyInt32 int32 + +//go:wasmexport good2 +func good2(MyInt32) {} // named type is ok + +//go:wasmexport good3 +func good3() int32 { return 0 } // one result is ok + +//go:wasmexport bad1 +func bad1(string) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport bad2 +func bad2(any) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport bad3 +func bad3(func()) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport bad4 +func bad4(uint8) {} // ERROR "go:wasmexport: unsupported parameter type" + +// Pointer types are not allowed, except unsafe.Pointer. +// Struct and array types are also not allowed. +// If proposal 66984 is accepted and implemented, we may allow them. + +//go:wasmexport bad5 +func bad5(*int32) {} // ERROR "go:wasmexport: unsupported parameter type" + +type S struct { x, y int32 } + +//go:wasmexport bad6 +func bad6(S) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport bad7 +func bad7(*S) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport bad8 +func bad8([4]int32) {} // ERROR "go:wasmexport: unsupported parameter type" + +//go:wasmexport toomanyresults +func toomanyresults() (int32, int32) { return 0, 0 } // ERROR "go:wasmexport: too many return values" -- 2.48.1