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

error in reconciler in vimeo/psalm:^1.1 #819

Closed
ghost opened this issue Jun 14, 2018 · 11 comments
Closed

error in reconciler in vimeo/psalm:^1.1 #819

ghost opened this issue Jun 14, 2018 · 11 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2018

still have to dig through our code for the cause, but there's something we're doing that's triggering this error in psalm 1.1

psalm
Scanning files...
Analyzing files...

Notice: Uninitialized string offset: 0 in vendor\vimeo\psalm\src\Psalm\Type\Reconciler.php on line 194

Notice: Uninitialized string offset: 0 in vendor\vimeo\psalm\src\Psalm\Type\Reconciler.php on line 199

Fatal error: Uncaught Psalm\Exception\TypeParseTreeException: Invalid type '' in vendor\vimeo\psalm\src\Psalm\Type.php:96
@muglug
Copy link
Collaborator

muglug commented Jun 14, 2018

Does it also occur with dev-master?

You can find the line it triggers on with --debug-by-line - either way it's time for another 1.x release.

@ghost
Copy link
Author

ghost commented Jun 15, 2018

on dev-master 47a40b2:

PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 32768 bytes) vendor\vimeo\psalm\src\Psalm\Codebase\Populator.php on line 434

back on ^1.1, the line occurs inside a try-catch block doing this:

            /**
            * @var array<int, static> $out
            */
            $out = array_filter(
                static::rows($ids),
                function (self $row) : bool {
                    return is_a($row, static::class);
                }
            );

changing the filter to this:

                function (self $row) : bool {
                    return is_a(get_class($row), static::class, true);
                }

resolves in this error message:
PossiblyInvalidArgument - file.php:340:17 - First parameter of closure passed to function array_filter expects T, possibly different type T|null provided

so looks like psalm is tripping up on the use of non-string is_a() ?

@muglug
Copy link
Collaborator

muglug commented Jun 15, 2018

What's the return type of self::$rows($ids)?

@weirdan
Copy link
Collaborator

weirdan commented Jun 15, 2018

Allowed memory size of 2097152 bytes exhausted

2MB is kinda tight. Psalm takes 19MB here on an empty project.

@muglug
Copy link
Collaborator

muglug commented Jun 15, 2018

Yeah 2MB isn't the default: https://github.com/vimeo/psalm/blob/master/src/psalm.php#L12

@ghost
Copy link
Author

ghost commented Jun 15, 2018

@muglug it's array<int, static|null>

@weirdan php.ini was set to memory_limit=128M, is now set to memory_limit=256M

@muglug
Copy link
Collaborator

muglug commented Jun 15, 2018

Fatal error aside, I think that’s the right complaint (the arg expects a non-null value). Unless array_filter already strips out non-null values?

@ghost
Copy link
Author

ghost commented Jun 15, 2018

@muglug the error is correctly reported with is_a(string, string, true), but it fouls up with is_a(object, string)

@muglug
Copy link
Collaborator

muglug commented Jun 15, 2018

Reproducible with

class A {
    /**
     * @return array<int, self|null>
     */
    public function getRows() : array {
        return [new self, null];
    }

    public function filter() : void {
        $arr = array_filter(
            static::getRows(),
            function (self $row) : bool {
                return is_a($row, static::class);
            }
        );
    }
}

@muglug muglug closed this as completed in 3afd605 Jun 15, 2018
@muglug
Copy link
Collaborator

muglug commented Jun 15, 2018

The latest 1.x branch has those updates - I'll try and get a release out today

@ghost
Copy link
Author

ghost commented Jun 18, 2018

ty

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

No branches or pull requests

2 participants