Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using nothing should behave like using noreturn value #9001

Open
muglug opened this issue Feb 14, 2022 · 0 comments
Open

Using nothing should behave like using noreturn value #9001

muglug opened this issue Feb 14, 2022 · 0 comments
Labels

Comments

@muglug
Copy link
Contributor

muglug commented Feb 14, 2022

Describe the bug

We have a pattern where we want to error any time someone uses a banned method:

Standalone code, or other way to reproduce the problem

abstract class Result {
	abstract public function getOne(): string;
	abstract public function getOther(): string;
}

final class ResultError extends Result {
	public function getOne(): noreturn { throw new \Exception('bad'); }
        // ^ The method `foo` is not compatible with the overridden method (Typing[4341])

	public function getOther(): nothing { throw new \Exception('bad'); }
        // this is allowed
}

function doThing(ResultError $result): void {
	echo $result->getOne();
	// ^ You are using the return value of a `noreturn` function (Typing[4133])
}

function doOtherThing(ResultError $result): void {
	echo $result->getOther();
        // this is allowed
}

Expected behavior

Error when using value from nothing-returning function or method

Optional-extra: Allow noreturn to act as the bottom type

Environment

  • Operating system: Docker Ubuntu
  • Installation method: hhvm/hhvm on dockerhub'
  • HHVM Version: 4.149.0-dev (rel) (non-lowptr)
@lexidor lexidor added the hack label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants