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

inconsistent behaviour of InvalidCast #1398

Closed
SignpostMarv opened this issue Feb 27, 2019 · 1 comment
Closed

inconsistent behaviour of InvalidCast #1398

SignpostMarv opened this issue Feb 27, 2019 · 1 comment
Labels

Comments

@SignpostMarv
Copy link
Contributor

issue

  • array manually type-hinted to scalar|array|object|resource|null does not flag up MixedAssignment (could go either way on this one)

behaves as expected

  • typehinted array correctly flags up InvalidCast
  • array manually typed-hinted to scalar|array|object|null does flag up InvalidCast

does not behave as expected

  • array assigned to mixed does not flag up InvalidCast
  • array manually type-hinted to scalar|array|object|resource|null (aka mixed) does not flag up InvalidCast

repro

<?php
$a = [];

echo (string) $a;

/**
* @var mixed
*/
$b = [];

echo (string) $b;

/**
* @var scalar|array|object|resource|null
*/
$c = [];

echo (string) $c;

/**
* @var scalar|array|object|null
*/
$d = [];

echo (string) $d;

Psalm output (using commit 119687f):

ERROR: InvalidCast - 4:6 - array<empty, empty> cannot be cast to string

INFO: MixedAssignment - 9:1 - Cannot assign $b to a mixed type

ERROR: InvalidCast - 25:6 - array<array-key, mixed>|scalar|object|null cannot be cast to string

@muglug
Copy link
Collaborator

muglug commented Mar 1, 2019

It's really just a failure of

/**
* @var array|resource
*/
$c = [];

echo (string) $c;

to emit an error

@muglug muglug added the bug label Mar 1, 2019
@muglug muglug closed this as completed in d1cf9d6 Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants