From e7201cfa9fe638053b7c269c23bf408223600bc9 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 23 Feb 2023 15:47:44 -0800 Subject: [PATCH] go/types, types2: add isTypeLit predicate Preparation for next CL. Change-Id: I5ef170a04577d8aea10255e304357bdbea4935a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/470919 TryBot-Result: Gopher Robot Reviewed-by: Robert Findley Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer Auto-Submit: Robert Griesemer --- src/cmd/compile/internal/types2/predicates.go | 11 +++++++++++ src/go/types/predicates.go | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cmd/compile/internal/types2/predicates.go b/src/cmd/compile/internal/types2/predicates.go index 2e6067652b..c92c1dc292 100644 --- a/src/cmd/compile/internal/types2/predicates.go +++ b/src/cmd/compile/internal/types2/predicates.go @@ -64,6 +64,17 @@ func hasName(t Type) bool { return false } +// isTypeLit reports whether t is a type literal. +// This includes all non-defined types, but also basic types. +// isTypeLit may be called with types that are not fully set up. +func isTypeLit(t Type) bool { + switch t.(type) { + case *Named, *TypeParam: + return false + } + return true +} + // isTyped reports whether t is typed; i.e., not an untyped // constant or boolean. isTyped may be called with types that // are not fully set up. diff --git a/src/go/types/predicates.go b/src/go/types/predicates.go index 903b1445e9..cf02a8cab5 100644 --- a/src/go/types/predicates.go +++ b/src/go/types/predicates.go @@ -66,6 +66,17 @@ func hasName(t Type) bool { return false } +// isTypeLit reports whether t is a type literal. +// This includes all non-defined types, but also basic types. +// isTypeLit may be called with types that are not fully set up. +func isTypeLit(t Type) bool { + switch t.(type) { + case *Named, *TypeParam: + return false + } + return true +} + // isTyped reports whether t is typed; i.e., not an untyped // constant or boolean. isTyped may be called with types that // are not fully set up. -- 2.48.1