I don't think the empty case should be the problem. If it can't infer the type, sum just throws an error. So test1(r) actually always returns the same type for r::Array{Float64} in any case where it returns a value at al.
The real problem is that eltype(t^2 for t in rand(10)) returns Any.