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

Class constants using bitwise operations are mixed #2149

Closed
Tracked by #9
SignpostMarv opened this issue Sep 19, 2019 · 2 comments
Closed
Tracked by #9

Class constants using bitwise operations are mixed #2149

SignpostMarv opened this issue Sep 19, 2019 · 2 comments

Comments

@SignpostMarv
Copy link
Contributor

possibly related to #2139 and #1551

bitwise const: https://psalm.dev/r/222baddf7b

<?php
class Foo {
  const BAR = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5;
  
  public int $flags;
  
  public function __construct() {
    $this->flags = self::BAR;
  }
}

Psalm output (using commit e9cd791):

INFO: MixedAssignment - 8:5 - Cannot assign $this->flags to a mixed type

bitwise literal: https://psalm.dev/r/f6b76e4d2f

<?php
class Foo {
  const BAR = 1 | 2;
  
  public int $flags;
  
  public function __construct() {
    $this->flags = self::BAR;
  }
}

Psalm output (using commit e9cd791):

INFO: MixedAssignment - 8:5 - Cannot assign $this->flags to a mixed type

p.s. 1 | "nope" = 1, with a warning.

@SignpostMarv
Copy link
Contributor Author

@muglug - I'm digging around in the code, and it appears that psalm does track the binary or operation, leaving Psalm\Type\Atomic\TInt as the sole member of a union, but the class const fetch comes back as mixed (with and without hoist consts)

@weirdan
Copy link
Collaborator

weirdan commented Aug 17, 2020

Can't reproduce anymore.

@weirdan weirdan closed this as completed Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants