Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ public function testBug5091(): void
$this->assertNoErrors($errors);
}

public function testBug9346(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-9346.php');
$this->assertNoErrors($errors);
}

public function testBug9459(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-9459.php');
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-9542.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-9803.php');
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/PhpDoc/data/bug-10594.php');

yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-9346.php');
}

/**
Expand Down
64 changes: 64 additions & 0 deletions tests/PHPStan/Analyser/data/bug-9346.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Bug9346;

use DateTime;

/**
* @phpstan-type MyType array{
* key?: string,
* }
*/
class Test
{
/**
* @param MyType $params
*/
public function create(array $params = []): object
{
return new class($params) {
/**
* @param MyType $params
*/
public function __construct(private array $params)
{
}
};
}
}

/**
* @phpstan-type FooJson array{bar: string}
*/
interface Foo
{
/**
* @phpstan-return FooJson
*/
public function sayHello(DateTime $date): array;
}

/**
* @phpstan-import-type FooJson from Foo
*/
class HelloWorld
{
public function createFoo(): Foo
{
$foo = new class() implements Foo {
/**
* @phpstan-var FooJson $var
*/
private array $var = ['bar' => 'baz'];

/**
* @phpstan-return FooJson
*/
public function sayHello(DateTime $date): array
{
return $this->var;
}
};
return $foo;
}
}
Loading