Just modify Compat.jl so it offers compatibility with future versions of 
Julia ...

using Compat

@compat function g()::Int
    # stuff
end
function fg(args...) g() end # returns an Int, so it must return something

@compat function h()::Void
  # stuff
end
function fh(args...) h() end # returns Void, so it must return nothing




On Tuesday, May 24, 2016 at 6:30:19 PM UTC-4, Stefan Karpinski wrote:
>
> On Tue, May 24, 2016 at 5:08 PM, Steven G. Johnson <steve...@gmail.com 
> <javascript:>> wrote:
>
>> As Jeff says, the current behavior is consistent in that a block like 
>> begin...end has a value equal to its last expression in any other context, 
>> so it would be odd if begin...end in a function body did not have the same 
>> behavior. I mostly like the style of explicit "return" statements in 
>> functions, but I think this should be more of a linting thing.
>>
>
> What I proposed doesn't change anything about what any expression 
> evaluates to. The only thing it changes is that
>
> function f(args...)
>
>     # stuff
>
> end
>
>
> would *implicitly* mean
>
> function f(args...)
>     # stuff
>     return
> end
>
>
> That way unless you put an explicit return in a long form function, it 
> automatically returns nothing, avoiding accidentally returning the value of 
> the last expression. 
> In order to adjust for this change one would at most need to add a single 
> return at the end of long-form functions which are *intended* to return a 
> value. Short-form functions would not have to change and long-form 
> functions with explicit returns would not have to change.
>
> The problem with making this "a linting thing" is that we don't statically 
> know which expressions return nothing. When you see code like this:
>
> function f(args...)
>     # stuff
>     g()
> end
>
>
> should it be a lint warning or not? It depends on what g() returns: if g() 
> returns `nothing` then this code is fine; if g() returns a value, then we 
> are accidentally returning it. Whether the code passes linting depends on 
> the unknowable behavior of g(). Even if we did dynamic instrumentation, 
> there's a chance that g() could return `nothing` as a meaningful value (see 
> match). With the change I proposed, we can statically tell the difference 
> between an accidental return and an intentional one.
>

Reply via email to