hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Typed array type alias problem

Open tslettebo opened this issue 11 years ago • 3 comments

The following works:

<?hh // strict

type Test = array<int>;

f();

function f(array<int> $t = [1]): void
{
  var_dump($t);
}

However, if you change the function definition, changing "array" to "Test", it fails when you run it:

"Default value for parameter t with type Array needs to have the same type as the type hint Test "

Both versions pass the type checker.

tslettebo avatar Apr 06 '15 06:04 tslettebo

Hmm, looks like a bug here where we check the default value type at compile time. I don't see anything here dealing with the possibility of a type alias.

paulbiss avatar Apr 06 '15 15:04 paulbiss

We've run into this with shapes as well in 3.15.0-dev (2016-08-25).

https://3v4l.org/gWW08

HRMsimon avatar Aug 26 '16 01:08 HRMsimon

I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.

It appears like this problem was fixed at some point, but I can't find the blogpost for it. Your repro var_dump()'s array[1]{ [0] => int(1) }.

<<__EntryPoint>>
function main(): void {
  f();
}

type Test = array<int>;

function f(Test $t = varray[1]): void {
  var_dump($t);
}

lexidor avatar May 20 '20 20:05 lexidor