Skip to content

Commit

Permalink
[hack][builder pattern] Add issue description for PULSE_UNFINISHED_BU…
Browse files Browse the repository at this point in the history
…ILDER

Summary: Add issue description for PULSE_UNFINISHED_BUILDER

Reviewed By: davidpichardie

Differential Revision:
D65419581

Privacy Context Container: L1208441

fbshipit-source-id: f2159cbf64c599ac5dadd591240a52868df0d3f0
  • Loading branch information
geralt-encore authored and facebook-github-bot committed Nov 4, 2024
1 parent 9ac3f7a commit 325b99c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions infer/documentation/issues/PULSE_UNFINISHED_BUILDER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Classes adhering to builder pattern are usually expected to call a finalizer function at some point to produce final result based on values that were passed to a builder itself. If finalizer function hasn't been called then builder's data won't be consumed in any meaningful way and will just be discarded.

```hack
class MyBuilder {
private int $a = 0;
private int $b = 0;
public function setA(int $a): MyBuilder {
$this->a = $a;
return $this;
}
public function setB(int $b): MyBuilder {
$this->b = $b;
return $this;
}
public function saveX(): Awaitable<void> {
// typically do something involving IO
}
}
class BuilderTester {
public static function builderUserOK(): void {
$b = new MyBuilder(0);
$b->setA(42)->setB(97)->saveX();
}
public static function builderUserBad(): void {
$b = new MyBuilder(0);
$b->setA(42)->setB(97); // ERROR: saveX hasn't been called so the builder's data is discarded
}
}
```
3 changes: 2 additions & 1 deletion infer/src/base/IssueType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@ let pulse_unawaited_awaitable =

let pulse_unfinished_builder =
register ~enabled:false ~category:ResourceLeak ~id:"PULSE_UNFINISHED_BUILDER" Error Pulse
~hum:"Unfinished Builder" ~user_documentation:"See [RESOURCE_LEAK](#resource_leak)"
~hum:"Unfinished Builder"
~user_documentation:[%blob "./documentation/issues/PULSE_UNFINISHED_BUILDER.md"]


let pulse_uninitialized_const =
Expand Down

0 comments on commit 325b99c

Please sign in to comment.