Skip to content

Declared typed variable can be reassigned through closure use-by-reference #92

Description

@jefyokta

Description

TypePHP does not report an error when a declared variable is passed by reference into a closure and then assigned a value of a different type.

Reproduction

<?phpfunctionmain()
{
$num = 1;
$str = "str";
(staticfunction () use (&$num) {
$num = [];
})();
(staticfunction () use (&$str) {
$str = [];
})();
var_dump($num, $str);
}

Expected behavior

TypePHP should detect that $num and $str are inferred as incompatible types and report a type error when they are assigned an array through the referenced closure variable.

For example:

Cannot assign array to variable $num of type int
Cannot assign array to variable $str of type string

Actual behavior

TypePHP compiles the code without any error.

The closure receives $num and $str by reference:

use (&$num)
use (&$str)

and mutates their types inside the closure:

$num = [];
$str = [];

The type mutation is currently not detected.

Question outside the issue

Btw, are you focusing on refactoring right now?

I made some commits for my previous issue, but they require phpx's current dev-master version, so I haven't submitted the PR yet.

I noticed that your recent commits seem to be mostly focused on refactoring. What is the current focus of the project?

I've opened quite a few issues about type checking and other type-related features because I thought TypePHP was mainly focused on bringing stronger typing to PHP. But I understand that the project was renamed from PHP AOT to TypePHP, so the rename itself might not mean that the project's direction changed.

That said, it still seems like the project is mainly focused on the AOT compiler, while the type-related features are still fairly limited. What is the project's current focus and overall direction? I just want to make sure I'm contributing and opening issues in the right areas.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions