{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/hhvm/issues/5458","labels_url":"https://api.github.com/repos/facebook/hhvm/issues/5458/labels{/name}","comments_url":"https://api.github.com/repos/facebook/hhvm/issues/5458/comments","events_url":"https://api.github.com/repos/facebook/hhvm/issues/5458/events","html_url":"https://github.com/facebook/hhvm/issues/5458","id":85907570,"number":5458,"title":"Dynamic Shape not throwing at runtime","user":{"login":"bodinsamuel","id":1637651,"avatar_url":"https://avatars.githubusercontent.com/u/1637651?v=3","gravatar_id":"","url":"https://api.github.com/users/bodinsamuel","html_url":"https://github.com/bodinsamuel","followers_url":"https://api.github.com/users/bodinsamuel/followers","following_url":"https://api.github.com/users/bodinsamuel/following{/other_user}","gists_url":"https://api.github.com/users/bodinsamuel/gists{/gist_id}","starred_url":"https://api.github.com/users/bodinsamuel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodinsamuel/subscriptions","organizations_url":"https://api.github.com/users/bodinsamuel/orgs","repos_url":"https://api.github.com/users/bodinsamuel/repos","events_url":"https://api.github.com/users/bodinsamuel/events{/privacy}","received_events_url":"https://api.github.com/users/bodinsamuel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-07T14:29:45Z","updated_at":"2015-06-08T04:33:17Z","closed_at":null,"body":"Hi,\r\n\r\nI'v been struggling to understand how to use correctly shape with dynamic data.\r\nThis structure is very intersting for storing data but I found the lack of error throwing a little bit surprising.\r\nMaybe I'm wrong and there is an options or something to do this.\r\n\r\nFrom documentation, all examples are simple and works perfectly\r\n```php\r\ntype Point2D = shape('x' => int, 'y' => int);\r\n\r\n# hh_client = Success\r\n$myShape = shape('x' => 3, 'y' => 3);\r\n\r\n#hh_client = Error\r\n$myShape = shape('x' => true, 'y' => 3);\r\n\r\n#hh_client = Success\r\n$myDynamicVar = GetADataFromSomewhere();\r\n$myShape = shape('x' => $myDynamicVar, 'y' => 3);\r\n```\r\n\r\nThe third point is where I can't understand, hh_client report a succes which is normal as it cannot be checked statically. But there is no error at runtime.\r\n\r\nExecuting the script will predictively return an error on the second scenario but not the third. The shape will be created with a wrong structure.\r\nIf I need to check all my data structure manually I can only assume my script will be safe up to a certain point but I find doing this not so good as the point of Shape is to structure data without the hassle of doing this with array and checking everything by hand.\r\n\r\nThe documentation tell me \"However, HHVM will run this code correctly, most likely with unexpected results.\" I struggle to understand why?\r\nIs there a solution, or am I missing something?\r\n\r\nPS: running hhvm 3.8.0 nightly from today on Debian 8"},"comment":{"url":"https://api.github.com/repos/facebook/hhvm/issues/comments/109858307","html_url":"https://github.com/facebook/hhvm/issues/5458#issuecomment-109858307","issue_url":"https://api.github.com/repos/facebook/hhvm/issues/5458","id":109858307,"user":{"login":"paulbiss","id":1039792,"avatar_url":"https://avatars.githubusercontent.com/u/1039792?v=3","gravatar_id":"","url":"https://api.github.com/users/paulbiss","html_url":"https://github.com/paulbiss","followers_url":"https://api.github.com/users/paulbiss/followers","following_url":"https://api.github.com/users/paulbiss/following{/other_user}","gists_url":"https://api.github.com/users/paulbiss/gists{/gist_id}","starred_url":"https://api.github.com/users/paulbiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulbiss/subscriptions","organizations_url":"https://api.github.com/users/paulbiss/orgs","repos_url":"https://api.github.com/users/paulbiss/repos","events_url":"https://api.github.com/users/paulbiss/events{/privacy}","received_events_url":"https://api.github.com/users/paulbiss/received_events","type":"User","site_admin":false},"created_at":"2015-06-08T04:33:17Z","updated_at":"2015-06-08T04:33:17Z","body":"We don't type-check shapes at runtime, so that's why the runtime isn't complaining. If `GetADataFromSomewhere` is typed then Hack should be able to check it, if it's truly too dynamic to type-check then it's not valid Hack.\r\n\r\nIf this code isn't in a function then Hack isn't actually checking it since it doesn't operate on pseudomains.\r\n\r\n```php\r\ntype Point2D = shape('x' => int, 'y' => int);\r\nfunction GetADataFromSomewhere(): int { /* ... */ }\r\n\r\nfunction foo(): void {\r\n  $myShape = shape('x' => 3, 'y' => 3);\r\n  $myShape = shape('x' => true, 'y' => 3);\r\n  $myDynamicVar = GetADataFromSomewhere();\r\n  $myShape = shape('x' => $myDynamicVar, 'y' => 3);\r\n}\r\n```"}}