Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: check and warn byte in thrift idl #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单独对list分开一个判断吧来提示 binary,不然说明太长,更没人看

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 {
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"
Loading