Skip to content

Commit

Permalink
Stubs and generated arginfo: remove tentative returns from final meth…
Browse files Browse the repository at this point in the history
…ods (#16213)

A tentative return type is used to allow userland code that overrides a method
to not include a typehint without a fatal error; this is inapplicable to final
methods (including all methods of final classes), which cannot be overridden.
Remove the tentative return declarations, and update the build script to
complain about future additions.
  • Loading branch information
DanielEScherzer authored Oct 4, 2024
1 parent c8791e5 commit 2501cad
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
3 changes: 3 additions & 0 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,9 @@ public function __construct(
$this->attributes = $attributes;
$this->framelessFunctionInfos = $framelessFunctionInfos;
$this->exposedDocComment = $exposedDocComment;
if ($return->tentativeReturnType && $this->isFinalMethod()) {
throw new Exception("Tentative return inapplicable for final method");
}
}

public function isMethod(): bool
Expand Down
6 changes: 0 additions & 6 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,16 @@ final class ReflectionGenerator
{
public function __construct(Generator $generator) {}

/** @tentative-return-type */
public function getExecutingLine(): int {}

/** @tentative-return-type */
public function getExecutingFile(): string {}

/** @tentative-return-type */
public function getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT): array {}

/** @tentative-return-type */
public function getFunction(): ReflectionFunctionAbstract {}

/** @tentative-return-type */
public function getThis(): ?object {}

/** @tentative-return-type */
public function getExecutingGenerator(): Generator {}

public function isClosed(): bool {}
Expand Down
26 changes: 13 additions & 13 deletions ext/reflection/php_reflection_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions ext/spl/spl_directory.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public function __toString(): string {}
/** @tentative-return-type */
public function __debugInfo(): array {}

/**
* @tentative-return-type
*/
#[\Deprecated(since: '8.2')]
final public function _bad_state_ex(): void {}
}
Expand Down
15 changes: 8 additions & 7 deletions ext/spl/spl_directory_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2501cad

Please sign in to comment.