From 9b4a9587224d1c3a92467fb6ad064797a0cc56d1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sat, 28 Oct 2023 15:14:01 +0800 Subject: [PATCH] gox.IsTypeEx --- builtin_test.go | 15 +++++++++++++++ type_var_and_const.go | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/builtin_test.go b/builtin_test.go index 32374147..3e43a63f 100644 --- a/builtin_test.go +++ b/builtin_test.go @@ -62,6 +62,21 @@ func TestExportFields(t *testing.T) { } } +func TestIsTypeEx(t *testing.T) { + pkg := types.NewPackage("", "foo") + o := NewInstruction(0, pkg, "bar", lenInstr{}) + if !IsTypeEx(o.Type()) { + t.Fatal("IsTypeEx: not Instruction?") + } + of := NewOverloadFunc(0, pkg, "bar") + if !IsTypeEx(of.Type()) { + t.Fatal("IsTypeEx: not OverloadFunc?") + } + if IsTypeEx(tyInt) { + t.Fatal("IsTypeEx: not tyInt?") + } +} + func TestGetBuiltinTI(t *testing.T) { pkg := NewPackage("", "foo", nil) cb := &pkg.cb diff --git a/type_var_and_const.go b/type_var_and_const.go index ef1e80c4..447b5b02 100644 --- a/type_var_and_const.go +++ b/type_var_and_const.go @@ -901,3 +901,17 @@ func Lookup(scope *types.Scope, name string) (obj types.Object) { } // ---------------------------------------------------------------------------- + +// IsTypeEx returns if t is a gox extended type or not. +func IsTypeEx(t types.Type) (ok bool) { + switch v := t.(type) { + case *instructionType: + return true + case *types.Signature: + _, ok = CheckFuncEx(v) + return + } + return false +} + +// ----------------------------------------------------------------------------