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

Regression between 1.10.10 and 1.10.51 #10377

Closed
llaville opened this issue Jan 5, 2024 · 11 comments
Closed

Regression between 1.10.10 and 1.10.51 #10377

llaville opened this issue Jan 5, 2024 · 11 comments

Comments

@llaville
Copy link

llaville commented Jan 5, 2024

Bug report

I'm currently working to polish code on branch 1.1 of my project https://github.com/llaville/sarif-php-sdk with help of PHPStan

And I've noticed a possible regression between version 1.10.10 and 1.10.51 !

All seems good with 1.10.51

phpstan-1-10-51

But I got at least one issue not detected with 1.10.51, but 1.10.10 found it

phpstan-1-10-10

My config file is :

parameters:
    level: 9
    paths:
        - ../../src/
        - ../../examples/
    treatPhpDocTypesAsCertain: false
    ignoreErrors:
        -
            message: "#^Unreachable statement \\- code above always terminates\\.$#"
            path: ../../src/SarifLog.php

Code snippet that reproduces the problem

https://phpstan.org/r/e1376c55-7033-4477-a8f4-31f960cd4797

Expected output

[ERROR] Found 1 error

Did PHPStan help you today? Did it make you happy in any way?

No response

@llaville
Copy link
Author

llaville commented Jan 5, 2024

Commit llaville/sarif-php-sdk@a9a56bb fixed issue still pending and now my codebase is now PHPStan 1.10.51 rule 9 compatible !

@ondrejmirtes
Copy link
Member

Your code snippet shows only a trait. Traits are analysed in context of each class that uses them. If I use the trait, the error is reported: https://phpstan.org/r/2d2e00e1-f6f0-4f3d-b4cf-925ecad4c440

Learn more: https://phpstan.org/blog/how-phpstan-analyses-traits

@llaville
Copy link
Author

llaville commented Jan 5, 2024

If I analyse all source code as shown by screenshot, with same config file and code, v1.10.10 detect issue, while 1.10.51 do not.

@ondrejmirtes
Copy link
Member

In that case the reproduction is not faithful enough. If you struggle to reproduce the problem in the playground, you can also create a small reproducing repository that shows the problem.

You can also pin-point down the specific PHPStan version that broke this.

@ondrejmirtes
Copy link
Member

I'll reopen if you provide a reproduction.

@llaville
Copy link
Author

llaville commented Jan 6, 2024

Hello @ondrejmirtes

Here is a workflow to reproduce issue. I've tested it and run it on my private repo, but I found at least when behavior became to change.
Until version 1.10.22, all versions gave the same results in same context as the v1.10.10, but since 1.10.23 it has changed.

Hope you'll reconsider this as a regression ?

NOTE:

  • 8162500edf9254f8e83635b4b933dcade90d7c7e hash commit on my llaville/sarif-php-sdk is the source code to test before I fixed it with with a phpDoc block => llaville/sarif-php-sdk@a9a56bb
    See workflow given at bottom of this comment

phpstan-1-10-22

phpstan-1-10-23

And now the GitHub Workflow I've used to test regression !
As you can trigger it, you can change version of PHPStan to test (PHAR download)

---
# https://github.com/phpstan/phpstan/issues/10377
name: PHPStan issue 10377

on:
  workflow_dispatch:
    # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
    inputs:
      phpstan-version:
        description: "PHPStan latest version"
        required: false
        type: string
        default: "1.10.51"

jobs:
  phpstan:
    name: PHPStan

    runs-on: "${{ matrix.operating-system }}"

    strategy:
      fail-fast: false

      matrix:
        operating-system:
          - "ubuntu-22.04"

        php-version:
          - "8.2"

        phpstan-version:
          - "1.10.10"
          - ${{ github.event.inputs.phpstan-version }}

    steps:
      -   # https://github.com/actions/checkout
        name: Checkout Code
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
          repository: llaville/sarif-php-sdk
          ref: 8162500edf9254f8e83635b4b933dcade90d7c7e

      -   # https://github.com/shivammathur/setup-php
        name: Setup PHP runtime
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}
          coverage: "none"

      - name: "Download phpstan.phar"
        run: |
          curl -Ls https://github.com/phpstan/phpstan/releases/download/${{ matrix.phpstan-version }}/phpstan.phar -o /usr/local/bin/phpstan
          chmod +x /usr/local/bin/phpstan

      - # https://github.com/ramsey/composer-install
          name: Install Composer dependencies
          uses: ramsey/composer-install@v2
          with:
            dependency-versions: "highest"
            composer-options: "--prefer-dist --no-scripts"

      - # Analyse source code with PHAR artifact of PHPStan 1.10.x
          name: Analyze source code
          shell: bash
          run: |
            /usr/local/bin/phpstan analyse --no-ansi -c "${GITHUB_WORKSPACE}/.github/linters/phpstan.neon.dist" --debug -vvv

@llaville
Copy link
Author

llaville commented Jan 6, 2024

Probably because of what has applied on https://github.com/phpstan/phpstan/releases/tag/1.10.23, seen on release notes (chunk below) :

Fix processing traits with renamed methods (phpstan/phpstan-src@c6035f3), #7198, #6039, #4758

@ondrejmirtes
Copy link
Member

Alright so on 1.10.22 the error is:

 ------ -----------------------------------------------------------------------------------------------
  Line   src/Property/RequestParameters.php (in context of class Bartlett\Sarif\Definition\WebRequest)
 ------ -----------------------------------------------------------------------------------------------
  29     Property Bartlett\Sarif\Definition\WebRequest::$parameters (array<string>) does not accept
         array.
 ------ -----------------------------------------------------------------------------------------------

On 1.10.23 the error disappears.

Class WebRequest uses trait RequestParameters with RequestParameters::addAdditionalProperties insteadof Headers.

The error is reported inside RequestParameters::addAdditionalProperties method. The method should be continued to analyse. Which means this really is a bug.

@ondrejmirtes ondrejmirtes reopened this Jan 6, 2024
@ondrejmirtes
Copy link
Member

Here's a straightforward reproduction: https://phpstan.org/r/00447904-0c4f-433e-9f94-740916dd4aba

Line 32 should be analysed too.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@2270051

Copy link

github-actions bot commented Feb 7, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants