Skip to content

Commit

Permalink
[hack][builder pattern] Add FP test case with not finalised builder t…
Browse files Browse the repository at this point in the history
…hat doesn't have any method calls

Summary: We don't want to report builders that don't have any method calls. This may happen if builder finalisation is guarded by an external variable. This diffs adds the test case that highlights this problem.

Reviewed By: skcho

Differential Revision: D65338134

fbshipit-source-id: 4af7bbdd0d55ae9e3fbb81443d319443af2d800d
  • Loading branch information
geralt-encore authored and facebook-github-bot committed Nov 1, 2024
1 parent 989868f commit 17905f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions infer/tests/codetoanalyze/hack/pulse/builder.hack
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ class BuilderTester {
}
}

public static function FP_builderWithoutCallsOk(bool $flag): void {
$changes_made = false;
$b = new MyBuilder(0);

if ($flag) {
$b->setA(42);
$changes_made = true;
}

if ($changes_made) {
$b->saveX();
}
}

// now check builders recognised from the .inferconfig file
public static function testConfigBad(): void {
$b = new NoBuilderSuffix();
Expand Down
1 change: 1 addition & 0 deletions infer/tests/codetoanalyze/hack/pulse/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ booleans.hack, $root.Booleans::testBoolBad, 3, TAINT_ERROR, no_bucket, ERROR, [s
booleans.hack, $root.Booleans::testNullBad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value passed as argument `#0` to `$root.Booleans::testNullBad` with kind `Simple`,flows to this sink: value passed as argument `#0` to `$root.Level1::taintSink` with kind `Simple`], source: $root.Booleans::testNullBad, sink: $root.Level1::taintSink, tainted expression: $sc
booleans.hack, $root.Booleans::testNotNullBad, 3, TAINT_ERROR, no_bucket, ERROR, [source of the taint here: value passed as argument `#0` to `$root.Booleans::testNotNullBad` with kind `Simple`,flows to this sink: value passed as argument `#0` to `$root.Level1::taintSink` with kind `Simple`], source: $root.Booleans::testNotNullBad, sink: $root.Level1::taintSink, tainted expression: $sc
builder.hack, BuilderTester$static.builderUserBad, 3, PULSE_UNFINISHED_BUILDER, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `MyBuilder()` here,builder object becomes unreachable here]
builder.hack, BuilderTester$static.FP_builderWithoutCallsOk, 9, PULSE_UNFINISHED_BUILDER, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `MyBuilder()` here,builder object becomes unreachable here]
builder.hack, BuilderTester$static.testConfigBad, 2, PULSE_UNFINISHED_BUILDER, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `NoBuilderSuffix()` here,builder object becomes unreachable here]
builder.hack, BuilderTester$static.testConfigBad2, 3, PULSE_UNFINISHED_BUILDER, no_bucket, ERROR, [allocation part of the trace starts here,allocated by constructor `NoBuilderSuffix()` here,builder object becomes unreachable here]
builder.hack, BuilderTester2$static.testCreateBad, 3, PULSE_UNFINISHED_BUILDER, no_bucket, ERROR, [allocation part of the trace starts here,when calling `BuilderTester2$static.create` here,when calling `MyBuilder$static.__factory` here,allocated by constructor `MyBuilder()` here,builder object becomes unreachable here]
Expand Down

0 comments on commit 17905f0

Please sign in to comment.