Skip to content

Commit

Permalink
Account static methods as source of expressions that produce mutable …
Browse files Browse the repository at this point in the history
…values

Summary: As in title

Reviewed By: jamesjwu

Differential Revision: D7326427

fbshipit-source-id: f23ab59ae59aa3fae3d93121305eafe836bc9195
  • Loading branch information
vladima authored and hhvm-bot committed Mar 20, 2018
1 parent 82a61ab commit 42fd0c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hphp/hack/src/typing/typing_mutability.ml
Expand Up @@ -31,7 +31,8 @@ let rec expr_returns_owned_mutable
| T.Call (_, (_, T.Id id), _, _, _)
| T.Call (_, (_, T.Fun_id id), _, _, _) ->
fun_returns_mutable env id
| T.Call (_, ((_, (Some (_, Tfun fty))), T.Obj_get _), _, _, _) ->
| T.Call (_, ((_, (Some (_, Tfun fty))), T.Obj_get _), _, _, _)
| T.Call (_, ((_, (Some (_, Tfun fty))), T.Class_const _), _, _, _)->
fty.ft_returns_mutable
(* conditional operator returns owned mutable if both consequence and alternative
return owned mutable *)
Expand Down
21 changes: 21 additions & 0 deletions hphp/hack/test/typecheck/reactive/mutable_return1.php
@@ -0,0 +1,21 @@
<?hh // strict

class A {
<<__Rx, __Mutable>>
public function __construct(private int $x) {
}
<<__Rx, __MutableReturn>>
public static function get(): A {
return new A(1);
}
<<__Rx, __Mutable>>
public function setX(int $newX): void {
$this->x = $newX;
}
}

<<__Rx>>
function f(): void {
$a = A::get();
$a->setX(5);
}
1 change: 1 addition & 0 deletions hphp/hack/test/typecheck/reactive/mutable_return1.php.exp
@@ -0,0 +1 @@
No errors

0 comments on commit 42fd0c9

Please sign in to comment.