Skip to content

Commit c4848ea

Browse files
committed
Don't store scalar values in resolvedTypes
1 parent 1dc7058 commit c4848ea

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Analyser/MutatingScope.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,19 @@ public function getAnonymousFunctionReturnType(): ?Type
797797
/** @api */
798798
public function getType(Expr $node): Type
799799
{
800+
if ($node instanceof Node\Scalar\Int_) {
801+
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
802+
} elseif ($node instanceof String_) {
803+
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
804+
} elseif ($node instanceof Node\Scalar\Float_) {
805+
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
806+
} elseif ($node instanceof ConstFetch) {
807+
$loweredConstName = strtolower($node->name->toString());
808+
if (in_array($loweredConstName, ['true', 'false', 'null'], true)) {
809+
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
810+
}
811+
}
812+
800813
if ($node instanceof GetIterableKeyTypeExpr) {
801814
return $this->getIterableKeyType($this->getType($node->getExpr()));
802815
}
@@ -1295,11 +1308,7 @@ private function resolveType(string $exprString, Expr $node): Type
12951308
});
12961309
}
12971310

1298-
if ($node instanceof Node\Scalar\Int_) {
1299-
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
1300-
} elseif ($node instanceof String_) {
1301-
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
1302-
} elseif ($node instanceof Node\Scalar\InterpolatedString) {
1311+
if ($node instanceof Node\Scalar\InterpolatedString) {
13031312
$resultType = null;
13041313
foreach ($node->parts as $part) {
13051314
if ($part instanceof InterpolatedStringPart) {
@@ -1316,8 +1325,6 @@ private function resolveType(string $exprString, Expr $node): Type
13161325
}
13171326

13181327
return $resultType ?? new ConstantStringType('');
1319-
} elseif ($node instanceof Node\Scalar\Float_) {
1320-
return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this));
13211328
} elseif ($node instanceof Expr\CallLike && $node->isFirstClassCallable()) {
13221329
if ($node instanceof FuncCall && $node->name instanceof Expr) {
13231330
$callableType = $this->getType($node->name);

0 commit comments

Comments
 (0)