-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for handling of
ok
form for functions/methods (#157)
This pull request introduces support for the `ok` form in both user-defined and library functions and methods. The implementation addresses false positives, such as those identified in issue #77. Currently, the feature is designed to handle explicit boolean returns, specifically in the form of `return r0, r1, ..., true`. Support for expression-based returns (e.g., `return r0, r1, ..., flag` or `return r0, r1, ..., isOk()`) is tricky, as tracking boolean types is currently not supported in NilAway. We can handle this scenario in the future. [Closes #77 ] [Depends on #156 ]
- Loading branch information
1 parent
71d1444
commit c4313bf
Showing
8 changed files
with
974 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
testdata/src/go.uber.org/contracts/namedtypes/namedtypes.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2023 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package namedtypes: This package tests that named types are correctly handled for contract types (e.g., error | ||
// returning functions and ok-form for functions) | ||
package namedtypes | ||
|
||
// the below test uses the built-in name `bool` for creating a user-defined named type. However, the logic for determining | ||
// an ok-form function should not depend on the name `bool`, but the underlying type. This test ensures that the logic. | ||
type bool int | ||
|
||
func retPtrBoolNamed() (*int, bool) { | ||
return nil, 0 | ||
} | ||
|
||
func testNamedBool() { | ||
if v, ok := retPtrBoolNamed(); ok == 0 { | ||
_ = *v // want "dereferenced" | ||
} | ||
} | ||
|
||
// Similar to the above test, but with the built-in name `error` | ||
type error int | ||
|
||
func retPtrErrorNamed() (*int, error) { | ||
return nil, 0 | ||
} | ||
|
||
func testNamedError() { | ||
if v, ok := retPtrErrorNamed(); ok == 0 { | ||
_ = *v // want "dereferenced" | ||
} | ||
} |
Oops, something went wrong.