diff --git a/stub/returns.zep b/stub/returns.zep index 702930d26..17a2ec9a5 100644 --- a/stub/returns.zep +++ b/stub/returns.zep @@ -3,6 +3,8 @@ namespace Stub; class Returns { + protected stringDefaultNull = null; + public function testReturnCast1() -> int { return (int) 5.0; @@ -36,4 +38,12 @@ class Returns { return "Return back"; } + + /** + * @issue https://github.com/zephir-lang/zephir/issues/1991 + */ + public function returnNullOnString() -> string + { + return this->stringDefaultNull; + } } diff --git a/tests/Extension/ReturnsTest.php b/tests/Extension/ReturnsTest.php index 43c052d98..d2da1ed39 100644 --- a/tests/Extension/ReturnsTest.php +++ b/tests/Extension/ReturnsTest.php @@ -51,4 +51,16 @@ public function testShouldReturnWithoutParameterStaticVersion(): void { $this->assertSame('Return back', Returns::returnWithoutParameter()); } + + /** + * @issue https://github.com/zephir-lang/zephir/issues/1991 + */ + public function testIssue1991ShouldThrow(): void + { + $tester = new Returns(); + + $this->expectException(\TypeError::class); + + $tester->returnNullOnString(); + } }