You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Concerning this discussion, here is a feature request (I'm not very sure about the name of the feature itself)
After a few tries and thanks to the help of Copilot (this is my first time working with Hacklang) I've been able to replicate the feature request:
classRef<T>
{
publicfunction__construct(privateT$value)
{
}
publicfunctionzip<TOther>(Ref<TOther> $other) : Ref<(T, TOther)>
{
returnnewRef(tuple($this->value, $other->value));
}
publicfunctionunzip<T1, T2>() : (Ref<T1>, Ref<T2>) whereT = (T1, T2)
{
returntuple(
newRef($this->value[0]),
newRef($this->value[1]),
);
}
}
functionexample1(): void
{
$a=newRef(1); // Ref<int>$b=newRef('foo'); // Ref<string>$c=$a->zip($b); // Ref<(int, string)>$d=$c->unzip(); // (Ref<int>, Ref<string>)
}
functionexample2(): void
{
$a=newRef(1); // Ref<int>// Typing[4323] A where type constraint is violated here [1]// -> This is the method with where type constraints [2]// -> Expected (_, _) [3]// -> But got int [4]$b=$a->unzip();
}
functionexample3(): void
{
$a=newRef(tuple(1, tuple(false, 4.20))); // Ref<(int, (bool, float))>$b=$a->unzip(); // (Ref<int>, Ref<(bool, float)>)// Typing[4323] A where type constraint is violated here [1]// -> This is the method with where type constraints [2]// -> Expected (_, _) [3]// -> But got int [4]$c=$b[0]->unzip();
$d=$b[1]->unzip(); // (Ref<bool>, Ref<float>)
}
I still think this is similar to @psalm-if-this-is in practice, as it's a way to set the template type based on a condition.
Did PHPStan help you today? Did it make you happy in any way?
It raises the quality bar of all the projects that I love!
The text was updated successfully, but these errors were encountered:
Feature request
Concerning this discussion, here is a feature request (I'm not very sure about the name of the feature itself)
After a few tries and thanks to the help of Copilot (this is my first time working with Hacklang) I've been able to replicate the feature request:
I still think this is similar to
@psalm-if-this-is
in practice, as it's a way to set the template type based on a condition.Did PHPStan help you today? Did it make you happy in any way?
It raises the quality bar of all the projects that I love!
The text was updated successfully, but these errors were encountered: