From bcdf1499f26df535d28e19c9717c82e02fb3ef8e Mon Sep 17 00:00:00 2001 From: HeyJavaBean Date: Fri, 8 Nov 2024 14:04:18 +0800 Subject: [PATCH] optimize: check byte in thrift idl --- semantic/checker.go | 17 +++++++++++++++++ version/version.go | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/semantic/checker.go b/semantic/checker.go index 40f0787..de92972 100644 --- a/semantic/checker.go +++ b/semantic/checker.go @@ -145,11 +145,28 @@ func (c *checker) CheckStructLikes(t *parser.Thrift) (warns []string, err error) warns = append(warns, fmt.Sprintf("non-positive ID %d of field %q in %q", f.ID, f.Name, s.Name)) } + if containByteType(f.Type) { + warns = append(warns, fmt.Sprintf("field %q in %q is still using 'byte'. The 'byte' type is a compatibility alias for 'i8'. Use 'i8' to emphasize the signedness of this type. If you want to generate '[]byte', please use 'binary' in thrift IDL.", + f.Name, s.Name)) + } } } return } +func containByteType(t *parser.Type) bool { + if parser.Typename2TypeID(t.Name) == parser.BYTE { + return true + } + if t.KeyType != nil && containByteType(t.KeyType) { + return true + } + if t.ValueType != nil && containByteType(t.ValueType) { + return true + } + return false +} + // CheckUnions checks the semantics of union nodes. func (c *checker) CheckUnions(t *parser.Thrift) (warns []string, err error) { for _, u := range t.Unions { diff --git a/version/version.go b/version/version.go index 20fcf80..a68f943 100644 --- a/version/version.go +++ b/version/version.go @@ -14,4 +14,4 @@ package version -const ThriftgoVersion = "0.3.18" +const ThriftgoVersion = "0.3.19"