【问题标题】:unexpected T_OBJECT_OPERATOR but no TypeChecker errors (Hacklang)意外的 T_OBJECT_OPERATOR 但没有 TypeChecker 错误 (Hacklang)
【发布时间】:2016-02-21 02:40:45
【问题描述】:
<?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)
    );
}

对于类型检查器来说两者都可以,但第二个导致致命错误

致命错误:语法错误,意外的 T_OBJECT_OPERATOR,期待 ')'

【问题讨论】:

  • 在 PHP 中这是非法语法,可以使用 (new DestinationsByCountry($id))-&gt;byKey ... 解决 - 不确定这是否适用于 hacklang?
  • 谢谢,这是我的错。这适用于hacklang。我只是对类型检查器对此感到困惑。

标签: hacklang


【解决方案1】:

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

类型检查器不抱怨的原因是it doesn't typecheck code at toplevel。如果这是在函数或方法中,我希望类型检查器会发现错误。如果这段代码实际上在函数或方法中,请file an issue on GitHub

【讨论】:

  • 这个已经有问题了,虽然应该更新示例以将代码包装在一个函数中(hh_client 仍然不报告错误):github.com/facebook/hhvm/issues/6809
  • 示例在严格模式下的类函数内部
猜你喜欢
  • 2014-09-08
  • 2013-12-28
  • 2012-11-03
  • 1970-01-01
  • 2011-07-15
  • 1970-01-01
  • 1970-01-01
  • 2023-02-06
  • 1970-01-01
相关资源
最近更新 更多