{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/571","repository_url":"https://api.github.com/repos/manastech/crystal","labels_url":"https://api.github.com/repos/manastech/crystal/issues/571/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/571/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/571/events","html_url":"https://github.com/manastech/crystal/issues/571","id":70275668,"number":571,"title":"The result of comparing signed and unsigned variables of the same size is inconsistent","user":{"login":"ssvb","id":78642,"avatar_url":"https://avatars.githubusercontent.com/u/78642?v=3","gravatar_id":"","url":"https://api.github.com/users/ssvb","html_url":"https://github.com/ssvb","followers_url":"https://api.github.com/users/ssvb/followers","following_url":"https://api.github.com/users/ssvb/following{/other_user}","gists_url":"https://api.github.com/users/ssvb/gists{/gist_id}","starred_url":"https://api.github.com/users/ssvb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssvb/subscriptions","organizations_url":"https://api.github.com/users/ssvb/orgs","repos_url":"https://api.github.com/users/ssvb/repos","events_url":"https://api.github.com/users/ssvb/events{/privacy}","received_events_url":"https://api.github.com/users/ssvb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/manastech/crystal/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-04-23T01:23:17Z","updated_at":"2016-02-22T16:15:02Z","closed_at":null,"body":"Let's take a look at the following test program:\r\n```\r\na = 4294967295_u32\r\nb = 0_i32\r\n\r\nputs \"a = #{a}\"\r\nputs \"b = #{b}\"\r\n\r\nif b > a\r\n  puts \"(b > a) is true\"\r\nelse\r\n  puts \"(b > a) is false\"\r\nend\r\n\r\nif a < b\r\n  puts \"(a < b) is true\"\r\nelse\r\n  puts \"(a < b) is false\"\r\nend\r\n```\r\nThe resulting output is\r\n```\r\na = 4294967295\r\nb = 0\r\n(b > a) is true\r\n(a < b) is false\r\n```\r\nThe statements \"(b > a) is true\" and \"(a < b) is false\" are obviously contradicting each other.\r\n\r\nC/C++ compilers usually issue a warning about mixed signed/unsigned comparisons even though the language standard defines deterministic (albeit somewhat convoluted) conversion rules:\r\nhttps://www.securecoding.cert.org/confluence/display/cplusplus/INT02-CPP.+Understand+integer+conversion+rules\r\n"},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/187249220","html_url":"https://github.com/manastech/crystal/issues/571#issuecomment-187249220","issue_url":"https://api.github.com/repos/manastech/crystal/issues/571","id":187249220,"user":{"login":"omninonsense","id":5641460,"avatar_url":"https://avatars.githubusercontent.com/u/5641460?v=3","gravatar_id":"","url":"https://api.github.com/users/omninonsense","html_url":"https://github.com/omninonsense","followers_url":"https://api.github.com/users/omninonsense/followers","following_url":"https://api.github.com/users/omninonsense/following{/other_user}","gists_url":"https://api.github.com/users/omninonsense/gists{/gist_id}","starred_url":"https://api.github.com/users/omninonsense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/omninonsense/subscriptions","organizations_url":"https://api.github.com/users/omninonsense/orgs","repos_url":"https://api.github.com/users/omninonsense/repos","events_url":"https://api.github.com/users/omninonsense/events{/privacy}","received_events_url":"https://api.github.com/users/omninonsense/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T16:15:02Z","updated_at":"2016-02-22T16:15:02Z","body":"@stugol Well file sizes are unsigned integers, so you should've used an unsigned integer to begin with. I understand the frustration and I'm sorry you feel that way.\r\n\r\nI don't think Crystal is as high level as you imagined it to be. It's a few steps up from C, but it's also a few steps down from Ruby.\r\n\r\nChecking the type during each comparison would be a performance waste.\r\n\r\nI don't think Implementing it is not the problem, but coming up with a good method is. If you see the solution, why don't you share it?"}}