Skip to content

Commit

Permalink
optimize: check byte in thrift idl
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed Nov 8, 2024
1 parent e76a88a commit cf37a53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions semantic/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
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 {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

package version

const ThriftgoVersion = "0.3.18"
const ThriftgoVersion = "0.3.19"

0 comments on commit cf37a53

Please sign in to comment.