Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default formatting removes semi colon, breaking code #774

Open
jdm204 opened this issue Oct 23, 2023 · 2 comments
Open

Default formatting removes semi colon, breaking code #774

jdm204 opened this issue Oct 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@jdm204
Copy link

jdm204 commented Oct 23, 2023

I assign to a variable in the condition of a while loop in this (working) code:

getdata() = rand() < 0.5 ? rand() : missing

function dowork()
    while !ismissing((val = getdata();))
        println(val^2)
    end
end

When I format the file with JuliaFormatter.format_file(), the semicolon is removed. The code then errors with “ERROR: MethodError: no method matching ismissing(; val::Float64)”, changing the behavior.

The versions are Julia 1.9.3, JuliaFormatter 1.0.36. I've tried it with the default and setting SciML style.

It has been pointed out that the code that breaks isn't the most readable. Originally posted here https://discourse.julialang.org/t/formatting-assignment-in-function-call/105269

@domluna domluna added the bug Something isn't working label Nov 22, 2023
@domluna
Copy link
Owner

domluna commented Nov 22, 2023

I think this will be easier to do when we swap CSTParser for JuliaSyntax but atm placing the semicolon in the right spot can be problematic since it's only captured by the tokenizer and not the parse tree

@dawbarton
Copy link

This also comes up with array concatenation. I have the code

    select!(data,
        [[:programme_group_code,
            :school_code,
            :domicile,
            :domicile_conversion,
            :domicile_size,
            :days_to_app,
            :days_to_offer,
            :registered]; columns])

that gets formatted to

    select!(data,
        [[:programme_group_code,
            :school_code,
            :domicile,
            :domicile_conversion,
            :domicile_size,
            :days_to_app,
            :days_to_offer,
            :registered] columns])

(i.e., changing a vcat to an hcat.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants