{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/13334","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/13334/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/13334/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/13334/events","html_url":"https://github.com/JuliaLang/julia/issues/13334","id":108560521,"number":13334,"title":"checkbounds return value","user":{"login":"garrison","id":91987,"avatar_url":"https://avatars.githubusercontent.com/u/91987?v=3","gravatar_id":"","url":"https://api.github.com/users/garrison","html_url":"https://github.com/garrison","followers_url":"https://api.github.com/users/garrison/followers","following_url":"https://api.github.com/users/garrison/following{/other_user}","gists_url":"https://api.github.com/users/garrison/gists{/gist_id}","starred_url":"https://api.github.com/users/garrison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garrison/subscriptions","organizations_url":"https://api.github.com/users/garrison/orgs","repos_url":"https://api.github.com/users/garrison/repos","events_url":"https://api.github.com/users/garrison/events{/privacy}","received_events_url":"https://api.github.com/users/garrison/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/doc","name":"doc","color":"02d7e1"},{"url":"https://api.github.com/repos/JuliaLang/julia/labels/error%20handling","name":"error handling","color":"02d7e1"},{"url":"https://api.github.com/repos/JuliaLang/julia/labels/up%20for%20grabs","name":"up for grabs","color":"0b02e1"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2015-09-27T20:56:10Z","updated_at":"2016-10-11T19:46:13Z","closed_at":null,"body":"I was a bit surprised to notice that the function `checkbounds(A::AbstractArray{T,N}, I...)` returns `true` if it does not throw a `BoundsError`.\r\n\r\n```\r\njulia> checkbounds(1:3, 4)\r\nERROR: BoundsError: attempt to access 1:3\r\n  at index [4]\r\n\r\njulia> checkbounds(1:3, 3)\r\ntrue\r\n```\r\n\r\nI would have expected it to return `nothing`, especially since the documentation makes no mention of return value:\r\n\r\n> Throw an error if the specified indexes are not in bounds for the given array. Subtypes of `AbstractArray` should specialize this method if they need to provide custom bounds checking behaviors.\r\n\r\nNote that there *is* another version of `checkbounds` that is explicitly asked to return a `Bool`:\r\n\r\n```\r\njulia> checkbounds(Bool, 3, 4)\r\nfalse\r\n\r\njulia> checkbounds(Bool, 3, 3)\r\ntrue\r\n```\r\n\r\nTwo possible solutions:\r\n\r\n1. change `checkbounds(A::AbstractArray{T,N}, I...)` to return `nothing` if it does not throw an error.  This will involve going through existing packages to make sure nobody is relying on the current behavior.\r\n2. decide that returning `true` is actually no accident, and modify the documentation to mention the return value.  If this decision is taken, it's especially important to make this explicit in the documentation, as subtypes of `AbstractArray` will want to also have their `checkbounds` return `true` to be consistent with the original interface (otherwise there can be subtle breakage).\r\n\r\nMy vote is for the first option, as returning `true` is redundant if no error is thrown."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/253023921","html_url":"https://github.com/JuliaLang/julia/issues/13334#issuecomment-253023921","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/13334","id":253023921,"user":{"login":"H-225","id":1348560,"avatar_url":"https://avatars.githubusercontent.com/u/1348560?v=3","gravatar_id":"","url":"https://api.github.com/users/H-225","html_url":"https://github.com/H-225","followers_url":"https://api.github.com/users/H-225/followers","following_url":"https://api.github.com/users/H-225/following{/other_user}","gists_url":"https://api.github.com/users/H-225/gists{/gist_id}","starred_url":"https://api.github.com/users/H-225/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/H-225/subscriptions","organizations_url":"https://api.github.com/users/H-225/orgs","repos_url":"https://api.github.com/users/H-225/repos","events_url":"https://api.github.com/users/H-225/events{/privacy}","received_events_url":"https://api.github.com/users/H-225/received_events","type":"User","site_admin":false},"created_at":"2016-10-11T19:46:13Z","updated_at":"2016-10-11T19:46:13Z","body":"This appears to have been fixed. (Checked on commit 6a1483b31d808acf90828613c793025054300101.)\r\n\r\n```julia\r\njulia> checkbounds(1:3, 4)\r\nERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [4]\r\n in throw_boundserror(::UnitRange{Int64}, ::Tuple{Int64}) at .\\abstractarray.jl:326\r\n in checkbounds(::UnitRange{Int64}, ::Int64) at .\\abstractarray.jl:283\r\n\r\njulia> checkbounds(1:3, 3)\r\n\r\njulia>\r\n```"}}
{"actor":{"display_login":"H-225"}}