Skip to content

Conversation

@whatUwant
Copy link
Contributor

Fixes #7551

@orklah orklah added PR: Need review release:fix The PR will be included in 'Fixes' section of the release notes labels Feb 22, 2022
@whatUwant
Copy link
Contributor Author

For some reason the failed test was run on php 8.0

  • Linux
    tests/EnumTest.php
      PHPUnit 9.5.14 by Sebastian Bergmann and contributors.
      
      Runtime:       PHP 8.0.15
      Configuration: /home/runner/work/psalm/psalm/phpunit.xml.dist
      Random Seed:   1645557663
      
      ...................E.................                             37 / 37 (100%)
      
      Time: 00:17.389, Memory: 52.00 MB
      
      There was 1 error:
      
      1) Psalm\Tests\EnumTest::testValidCode with data set "InterfacesWithProperties" ('<?php\n\n                    ...      ', array(), array(), '8.1')
      Psalm\Exception\CodeException: NoInterfaceProperties - src/somefile.php:11:72 - Interfaces cannot have properties
    
  • Windows
    ==> Setup PHP 
    √ PHP Installed PHP 8.0.16 
    

It passes on PHP 8.1.3

$ vendor/bin/phpunit tests/EnumTest.php
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.3
Configuration: /psalm/phpunit.xml.dist
Random Seed:   1645559189

.....................................                             37 / 37 (100%)

Time: 00:04.850, Memory: 54.00 MB

OK (37 tests, 53 assertions)

@weirdan
Copy link
Collaborator

weirdan commented Feb 22, 2022

On PHP 8.0 Psalm seems to be unaware that BackedEnum is a descendant of UnitEnum, so your test fails due to

in_array('UnitEnum', $codebase->getParentInterfaces($fq_class_name/*="ExtendedBackedEnum"*/))

check.
Below is the list of parent interfaces for ExtendedBackedEnum, running on 8.1 and 8.0 respectively:

dap> $codebase->getParentInterfaces($fq_class_name) // PHP 8.1
array(2)
dap> 
  backedenum: "BackedEnum"
  unitenum: "UnitEnum"
dap> $codebase->getParentInterfaces($fq_class_name) // PHP 8.0
array(1)
dap> 
  backedenum: "BackedEnum"

@whatUwant
Copy link
Contributor Author

Thanks for pointing it out. But I thought enum was available only since 8.1
https://www.php.net/manual/en/language.enumerations.overview.php

@whatUwant whatUwant marked this pull request as ready for review February 22, 2022 21:47
@AndrolGenhald
Copy link
Collaborator

They're only available in 8.1, but I believe we're trying to support analyzing a project requiring PHP 8.1 while running PHP < 8.1.

This should be fixable in stubs, it looks like BackedEnum is supposed to extend UnitEnum.

@weirdan weirdan merged commit 919775c into vimeo:4.x Feb 22, 2022
@weirdan
Copy link
Collaborator

weirdan commented Feb 22, 2022

Thanks!

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

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for properties in interfaces extending \UnitEnum & \BackedEnum

4 participants