Skip to content

Commit 56e426a

Browse files
committed
fix floats
1 parent 6a56c6f commit 56e426a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Type/FloatType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function toArrayKey(): Type
145145

146146
public function toCoercedArgumentType(bool $strictTypes): Type
147147
{
148+
if (!$strictTypes) {
149+
return TypeCombinator::union(new IntegerType(), new FloatType(), new StringType(), new BooleanType());
150+
}
151+
148152
return $this;
149153
}
150154

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,21 @@ public function doBar(): void
215215
assertType('string', $this->foo); // could be numeric-string
216216
}
217217
}
218+
219+
class FooFloatString
220+
{
221+
222+
public string $foo;
223+
224+
public function doFoo(float $b): void
225+
{
226+
$this->foo = $b;
227+
assertType('string', $this->foo); // could be numeric-string
228+
}
229+
230+
public function doBar(): void
231+
{
232+
$this->foo = 1.0;
233+
assertType('string', $this->foo); // could be numeric-string
234+
}
235+
}

0 commit comments

Comments
 (0)