From 40eac154c508f227a8b64d3edeca92a6f2cfc0f5 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 7 Jan 2025 00:15:42 +0800 Subject: [PATCH] Fixed issue #72. 1-more test case. --- internal/types/builtins.go | 21 +++++++++++++++++++++ internal/types/testdata/builtins.src | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/internal/types/builtins.go b/internal/types/builtins.go index 84ffa5be..536091e7 100644 --- a/internal/types/builtins.go +++ b/internal/types/builtins.go @@ -562,6 +562,27 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b // TODO(gri) "use" all arguments? return } + switch i { + case 0: + if !isPointer(x.typ) { + check.invalidArg(x.pos(), "%s is not a pointer", x) + return + } + case 1: + sig, ok := x.typ.(*Signature) + if !ok { + check.invalidArg(x.pos(), "%s is not a function", x) + return + } + if sig.Params().Len() != 1 || sig.Results().Len() != 0 { + check.invalidArg(x.pos(), "expect 1 parameter and 0 result for function, but found %d and %d", sig.Params().Len(), sig.Results().Len()) + return + } + if sig.Params().At(0).Type().String() != "u32" { + check.invalidArg(x.pos(), "expect u32 as parameter for function, but found %s", sig.Params().At(0).Type().String()) + return + } + } params[i] = x.typ } } diff --git a/internal/types/testdata/builtins.src b/internal/types/testdata/builtins.src index ecdba515..ce89091a 100644 --- a/internal/types/testdata/builtins.src +++ b/internal/types/testdata/builtins.src @@ -900,3 +900,10 @@ func trace2() { // trace(f2(), 1, 2, 3) // trace(f3(), 1, 2, 3, 4) } + +func setFinalizer1() { + i := 1 + setFinalizer(i, func(ptr: i32) {}) // ERROR is not a pointer + setFinalizer(&i, func(ptr: i32) {}) // ERROR expect u32 as parameter + setFinalizer(&i, func(ptr: u32, y: i64) {}) // ERROR expect 1 parameter and 0 result +}