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

PriorityQueue generics do not align with SplPriorityQueue #71

Closed
boesing opened this issue Aug 23, 2022 · 2 comments
Closed

PriorityQueue generics do not align with SplPriorityQueue #71

boesing opened this issue Aug 23, 2022 · 2 comments
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@boesing
Copy link
Member

boesing commented Aug 23, 2022

Bug Report

Q A
Version(s) 3.12.0

Summary

In one of the older releases, generics were added for the PriorityQueue.
I've updated to that and also got psalm bitching about SplPriorityQueue.
Now, since I want to fix both issues, I have to adapt different styles.

Current behavior

Generics for PriorityQueue needs to be written like:

PriorityQueue<TValue,TPriority>

Generics for SplPriorityQueue needs to be written like:
SplPriorityQueue<TPriority,TValue>

The latter feels more convenient, as its also aligned with arrays and keys. Since the priority queue is some kind of "array" as well, thats more inconvenient if I have to annotate the value as the key and the key as a value within the generic annotation in PriorityQueue implemetation.

How to reproduce

use Laminas\Stdlib\PriorityQueue;
use SplPriorityQueue;

final class Foo
{
    /** @var PriorityQueue<non-empty-string,int> */
    public PriorityQueue $laminas;
   
    /** @var PriorityQueue<int, non-empty-string> */
    public SplPriorityQueue $php;


    public function addString(): void
    {
        $this->php->insert('foo', count($this->php->count());
        $this->laminas->insert('foo', count($this->laminas->count());
    }
}

Expected behavior

use Laminas\Stdlib\PriorityQueue;
use SplPriorityQueue;

final class Foo
{
    /** @var PriorityQueue<int, non-empty-string> */
    public PriorityQueue $laminas;
   
    /** @var PriorityQueue<int, non-empty-string> */
    public SplPriorityQueue $php;


    public function addString(): void
    {
        $this->php->insert('foo', count($this->php->count());
        $this->laminas->insert('foo', count($this->laminas->count());
    }
}
@gsteel
Copy link
Member

gsteel commented Aug 23, 2022

This was my fault 😬 - Does #72 look good to you @boesing

@Ocramius Ocramius added this to the 3.13.0 milestone Aug 24, 2022
@Ocramius
Copy link
Member

Discussed in #72 - we will keep the "broken" generics order, to avoid introducing an intentional BC break in the type definition.

Annoying, but not a major issue, so we keep them in the current order, and just improved naming to reduce confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants