意外 T_OBJECT_OPERATOR 但没有 TypeChecker 错误 (Hacklang)

unexpected T_OBJECT_OPERATOR but no TypeChecker errors (Hacklang)

<?hh //strict 

foreach ($list as $id) {
    $items = new DestinationsByCountry($id);
    $remapped = $items->byKey('destination_id')->map($stringed ==> (int) $stringed);
    $this->ids->addAll($remapped);
}

foreach ($list as $id) {
    $this->ids->addAll(
        // ******* error line below *******
        new DestinationsByCountry($id)
            ->byKey('destination_id')
            ->map($stringed ==> (int) $stringed)
    );
}

类型检查器都可以,但第二个会导致致命错误

Fatal error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')'

正如上面评论中所指出的,在 PHP 和 Hack 语法中都需要在 (new DestinationsByCountry($id)) 周围加上括号。

类型检查器没有报错的原因是 it doesn't typecheck code at toplevel. If this had been inside a function or method, I expect the typechecker would have found the error. If this code was in fact inside a function or method, please do file an issue on GitHub.