我今天开始学习 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();
'y' 键被定义为整数,但是当我传递一个字符串时,没有显示错误。谢谢你的帮助 :)