Skip to content

Commit 4ca2d17

Browse files
committed
more precise bools
1 parent 1bea3db commit 4ca2d17

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/Type/BooleanType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function toArrayKey(): Type
114114
public function toCoercedArgumentType(bool $strictTypes): Type
115115
{
116116
if (!$strictTypes) {
117-
return TypeCombinator::union(new IntegerType(), new FloatType(), new StringType(), new BooleanType());
117+
return TypeCombinator::union($this->toInteger(), $this->toFloat(), $this->toString(), $this);
118118
}
119119

120120
return $this;

src/Type/Constant/ConstantBooleanType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function toArrayKey(): Type
114114
public function toCoercedArgumentType(bool $strictTypes): Type
115115
{
116116
if (!$strictTypes) {
117-
return TypeCombinator::union(new IntegerType(), new FloatType(), new StringType(), new BooleanType());
117+
return TypeCombinator::union($this->toInteger(), $this->toFloat(), $this->toString(), $this);
118118
}
119119

120120
return $this;

tests/PHPStan/Analyser/nsrt/bug-12393b.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ class FooBool
172172
public function doFoo(bool $b): void
173173
{
174174
$this->foo = $b;
175-
assertType('int', $this->foo);
175+
assertType('0|1', $this->foo);
176176
}
177177

178178
public function doBar(): void
179179
{
180180
$this->foo = true;
181-
assertType('int', $this->foo);
181+
assertType('1', $this->foo);
182182
}
183183
}
184184

@@ -190,15 +190,15 @@ class FooBoolString
190190
public function doFoo(bool $b): void
191191
{
192192
$this->foo = $b;
193-
assertType('string', $this->foo);
193+
assertType("''|'1'", $this->foo);
194194
}
195195

196196
public function doBar(): void
197197
{
198198
$this->foo = true;
199-
assertType('string', $this->foo);
199+
assertType("'1'", $this->foo);
200200
$this->foo = false;
201-
assertType('string', $this->foo);
201+
assertType("''", $this->foo);
202202
}
203203
}
204204

0 commit comments

Comments
 (0)