hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Using nothing should behave like using noreturn value

Open muglug opened this issue 3 years ago • 0 comments

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)

muglug avatar Feb 14 '22 18:02 muglug