Skip to content

Commit 8f9f60f

Browse files
committed
Revert "Enfore optional parameters in callable types"
This reverts commit 0910d70.
1 parent 0910d70 commit 8f9f60f

File tree

5 files changed

+4
-44
lines changed

5 files changed

+4
-44
lines changed

src/Type/CallableType.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,7 @@ public function describe(VerbosityLevel $level): string
146146
fn (): string => sprintf(
147147
'callable(%s): %s',
148148
implode(', ', array_map(
149-
static fn (ParameterReflection $param): string => sprintf(
150-
'%s%s%s',
151-
$param->isVariadic() ? '...' : '',
152-
$param->getType()->describe($level),
153-
$param->isOptional() && !$param->isVariadic() ? '=' : '',
154-
),
149+
static fn (ParameterReflection $param): string => sprintf('%s%s', $param->isVariadic() ? '...' : '', $param->getType()->describe($level)),
155150
$this->getParameters(),
156151
)),
157152
$this->returnType->describe($level),

src/Type/CallableTypeHelper.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public static function isParametersAcceptorSuperTypeOf(
2929

3030
$ourParameter = $ourParameters[$i];
3131
$ourParameterType = $ourParameter->getType();
32-
33-
if ($ourParameter->isOptional() && !$theirParameter->isOptional()) {
34-
return TrinaryLogic::createNo();
35-
}
36-
3732
if ($treatMixedAsAny) {
3833
$isSuperType = $theirParameter->getType()->accepts($ourParameterType, true);
3934
} else {

src/Type/ClosureType.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,7 @@ public function describe(VerbosityLevel $level): string
150150
static fn (): string => 'Closure',
151151
fn (): string => sprintf(
152152
'Closure(%s): %s',
153-
implode(', ', array_map(
154-
static fn (ParameterReflection $param): string => sprintf(
155-
'%s%s%s',
156-
$param->isVariadic() ? '...' : '',
157-
$param->getType()->describe($level),
158-
$param->isOptional() && !$param->isVariadic() ? '=' : '',
159-
),
160-
$this->parameters,
161-
)),
153+
implode(', ', array_map(static fn (ParameterReflection $parameter): string => sprintf('%s%s', $parameter->isVariadic() ? '...' : '', $parameter->getType()->describe($level)), $this->parameters)),
162154
$this->returnType->describe($level),
163155
),
164156
);

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,9 @@ public function testDiscussion7124(): void
763763

764764
$errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php');
765765
$this->assertCount(4, $errors);
766-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
766+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
767767
$this->assertSame(38, $errors[0]->getLine());
768-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int): bool given.', $errors[1]->getMessage());
768+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int): bool given.', $errors[1]->getMessage());
769769
$this->assertSame(45, $errors[1]->getLine());
770770
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[2]->getMessage());
771771
$this->assertSame(52, $errors[2]->getLine());
@@ -841,14 +841,6 @@ public function testBug7351(): void
841841
$this->assertNoErrors($errors);
842842
}
843843

844-
public function testBug7320(): void
845-
{
846-
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7320.php');
847-
$this->assertCount(1, $errors);
848-
$this->assertSame('Parameter #1 $c of function Bug7320\foo expects callable(int=): void, Closure(int): void given.', $errors[0]->getMessage());
849-
$this->assertSame(13, $errors[0]->getLine());
850-
}
851-
852844
/**
853845
* @param string[]|null $allAnalysedFiles
854846
* @return Error[]

tests/PHPStan/Analyser/data/bug-7320.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)