You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is some example code which I subsequently ran the formatter on.
cat ExampleModule2.jl
module ExampleModule2
function __init__()
global LOGFILEHANDLE = "notset"
return nothing
end
function write(logfilehandle, something)
println("writing $(something) to logfilehandle=$(logfilehandle)")
return 10
end
function exampleFunction()
LOGFILEHANDLE != "notset" && write(LOGFILEHANDLE, "examplestring")
end
function whatDoesExampleFunctionReturn()
tmp = exampleFunction()
println("type: $(typeof(tmp))")
println(tmp)
end
end
And here is the result of the format. I change the function names so that you can combine both of these into a single Julia file, if you wish to do so.
cat ExampleModule2.jl
module ExampleModule2
function __init__()
global LOGFILEHANDLE = "notset"
return nothing
end
function write(logfilehandle, something)
println("writing $(something) to logfilehandle=$(logfilehandle)")
return 10
end
function exampleFunction2()
return if LOGFILEHANDLE != "notset"
write(LOGFILEHANDLE, "examplestring")
end
end
function whatDoesExampleFunction2Return()
tmp = exampleFunction2()
println("type: $(typeof(tmp))")
println(tmp)
end
end
Here's the result of running both, combined into a single file ExampleModule2.jl:
because this isn't really a very sensible piece of code. But it does return false if the first condition is false and then it returns the return value of write otherwise.
The text was updated successfully, but these errors were encountered:
edward-bestx
changed the title
always_use_return and short_circuit_to_if`` bugalways_use_return and short_circuit_to_if` bug
Nov 24, 2024
I think I have found a bug which I think is related to the combination of two settings:
Here is some example code which I subsequently ran the formatter on.
And here is the result of the format. I change the function names so that you can combine both of these into a single Julia file, if you wish to do so.
Here's the result of running both, combined into a single file
ExampleModule2.jl
:What is important to note is that the formatter changes the behavior of
exampleFunction
.LOGFILEHANDLE = "notset"
,exampleFunction
returnsfalse
.exampleFunction2
returnsnothing
instead offalse
.Hopefully that is clear?
Maybe the formatter should do this instead?
It's actually kind of hard to say what it should do with
because this isn't really a very sensible piece of code. But it does return
false
if the first condition isfalse
and then it returns the return value ofwrite
otherwise.The text was updated successfully, but these errors were encountered: