Search code examples
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)
    );
}

Both is OK for the typecheker, but the second cause fatal error

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


Solution

  • As pointed out in the comments above, you need parenthesis around (new DestinationsByCountry($id)), in both PHP and in Hack syntax.

    The reason the typechecker doesn't complain is because 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.