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

#1991 - Fix throw on invalid return type #2196

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions stub/returns.zep
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace Stub;

class Returns
{
protected stringDefaultNull = null;

public function testReturnCast1() -> int
{
return (int) 5.0;
Expand Down Expand Up @@ -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;
}
}
12 changes: 12 additions & 0 deletions tests/Extension/ReturnsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}