Languages with dependent types can express things like “this offset is in bounds relative to this other array”, which is maybe what you’re thinking of.