Skip to content
Permalink
Browse files

Make @immutable work properly

  • Loading branch information...
muglug committed Aug 31, 2019
1 parent 4a38ab1 commit f20dc16295f15eb79a752f135e02f8dd6d0e38d3
Showing with 27 additions and 0 deletions.
  1. +1 −0 src/Psalm/Internal/Analyzer/CommentAnalyzer.php
  2. +26 −0 tests/PureAnnotationTest.php
@@ -868,6 +868,7 @@ public static function extractClassLikeDocblockInfo(
|| isset($parsed_docblock['specials']['psalm-mutation-free'])
) {
$info->mutation_free = true;
$info->external_mutation_free = true;
}
if (isset($parsed_docblock['specials']['psalm-external-mutation-free'])) {
@@ -99,6 +99,32 @@ function makesACounter(int $i) : Counter {
return $c;
}',
],
'canCreateImmutableObject' => [
'<?php
/** @immutable */
class A {
private string $s;
public function __construct(string $s) {
$this->s = $s;
}
public function getShort() : string {
return substr($this->s, 0, 5);
}
}
/** @psalm-pure */
function makeA(string $s) : A {
$a = new A($s);
if ($a->getShort() === "bar") {
return new A("foo");
}
return $a;
}'
],
];
}

0 comments on commit f20dc16

Please sign in to comment.
You can’t perform that action at this time.