Better type inference in SubArray construction

Fixes #5100
Merge pull request #5104 from JuliaLang/sjk/subarray-construction

Better type inference in SubArray construction