Skip to content

instanceof narrowing is not applied to repeated method calls #333

Description

@real420og

Verified on latest main

  • I have confirmed this bug still occurs when built from the latest main branch.

PHPantom version / commit

phpantom_lsp 0.9.0

Installation method

Pre-built binary from GitHub Releases

Operating system

macOS x86_64 (Intel)

Editor

Neovim

Bug description

instanceof narrowing is not applied to repeated method calls

PHPantom reports an error for the following code:

if ($this->getHttpKernel() instanceof TerminableInterface) {
$this->getHttpKernel()->terminate($request, $response);
}

Diagnostic:

Method 'terminate' not found on class 'Symfony\Component\HttpKernel\HttpKernelInterface'

I would expect no diagnostic here because the instanceof TerminableInterface check should narrow the type inside the if block, and TerminableInterface defines the terminate() method.

Image

Steps to reproduce

vendor/symfony/http-kernel/Kernel.php

if ($this->getHttpKernel() instanceof TerminableInterface) {
$this->getHttpKernel()->terminate($request, $response); * Method 'terminate' not found on class 'Symfony\Component\HttpKernel\HttpKernelInterface'
}

Error output or panic trace


.phpantom.toml

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions