小编Web*_*ere的帖子

hacklang的形状

我今天开始学习hacklang,现在我有点卡在形状上:http: //docs.hhvm.com/manual/en/hack.shapes.php

我理解形状的概念,它似乎对我很有用,但我无法理解为什么例如这段代码不会抛出任何错误:

<?hh

type Point2D = shape('x' => int, 'y' => int);

function dotProduct(Point2D $a, Point2D $b): int {
    return $a['x'] * $b['x'] + $a['y'] * $b['y'];
}

function main_sse(): void {
    echo dotProduct(shape('x' => 3, 'y' => 'this should cause an fatal error?'), shape('x' => 4, 'y' => 4));
}

main_sse();
Run Code Online (Sandbox Code Playgroud)

'y'键定义为整数,但是当我传递一个字符串时,不会显示错误.谢谢你的帮助 :)

hhvm hacklang

8
推荐指数
1
解决办法
2852
查看次数

标签 统计

hacklang ×1

hhvm ×1