Skip to content

v2 chokes on @main #950

@kousu

Description

@kousu

JuliaFormatter@2 fails to format code that uses the @main macro.

$ cat hello.jl 
function @main(ARGS::Vector{String})::Cint
        println("Hello, World")
    return 0
end
$ cat fmt.jl 
using Pkg;
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "2"))

using JuliaFormatter;
format_file(ARGS[1]);

$ julia --threads=auto -O3 --project=@temp  fmt.jl hello.jl 
   Resolving package versions...
    Updating `/tmp/jl_h89kFn/Project.toml`
  [98e50ef6] + JuliaFormatter v2.2.0
    Updating `/tmp/jl_h89kFn/Manifest.toml`
  [a80b9123] + CommonMark v0.9.1
  [c27321d9] + Glob v1.3.1
  [98e50ef6] + JuliaFormatter v2.2.0
⌅ [70703baa] + JuliaSyntax v0.4.10
  [aea7be01] + PrecompileTools v1.3.3
  [21216c6a] + Preferences v1.5.0
  [ade2ca70] + Dates v1.11.0
  [de0858da] + Printf v1.11.0
  [fa267f1f] + TOML v1.0.3
  [4ec0a83e] + Unicode v1.11.0
        Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m`
┌ Warning: Failed to format file /home/kousu/src/hello.jl due to a parsing error, skipping file
│   error =
│    ParseError:# Error @ line 1:10function @main(ARGS::Vector{String})::Cint#        └─────────────────────────┘ ── Invalid signature in function definition
└ @ JuliaFormatter ~/.julia/packages/JuliaFormatter/zLsPw/src/JuliaFormatter.jl:448

v1 works:

$ cat fmt.jl 
using Pkg;
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1"))

using JuliaFormatter;
format_file(ARGS[1]);

$ julia --threads=auto -O3 --project=@temp  fmt.jl hello.jl ; cat hello.jl
   Resolving package versions...
    Updating `/tmp/jl_aPdJJX/Project.toml`
⌃ [98e50ef6] + JuliaFormatter v1.0.62
    Updating `/tmp/jl_aPdJJX/Manifest.toml`
  [00ebfdb7] + CSTParser v3.4.3
⌅ [a80b9123] + CommonMark v0.8.16
  [34da2185] + Compat v4.18.1
  [a8cc5b0e] + Crayons v4.1.1
⌅ [864edb3b] + DataStructures v0.18.22
  [c27321d9] + Glob v1.3.1
⌃ [98e50ef6] + JuliaFormatter v1.0.62
  [bac558e1] + OrderedCollections v1.8.1
  [aea7be01] + PrecompileTools v1.3.3
  [21216c6a] + Preferences v1.5.0
  [0796e94c] + Tokenize v0.5.29
  [2a0f44e3] + Base64 v1.11.0
  [ade2ca70] + Dates v1.11.0
  [b77e0a4c] + InteractiveUtils v1.11.0
  [ac6e5ff7] + JuliaSyntaxHighlighting v1.12.0
  [d6f4376e] + Markdown v1.11.0
  [de0858da] + Printf v1.11.0
  [9a3f8284] + Random v1.11.0
  [ea8e919c] + SHA v0.7.0
  [f489334b] + StyledStrings v1.11.0
  [fa267f1f] + TOML v1.0.3
  [cf7118a7] + UUIDs v1.11.0
  [4ec0a83e] + Unicode v1.11.0
        Info Packages marked with ⌃ and ⌅ have new versions available. Those with ⌃ may be upgradable, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated -m`
function @main(ARGS::Vector{String})::Cint
    println("Hello, World")
    return 0
end
$ julia --version
julia version 1.12.1

I assume if it gets lost on that it will get lost if I build other apps using macros. Will it break on @ccallable too?

Still a newbie here so I don't know where I'd even start to go debugging this but hopefully there's something obvious to you syntax experts in here.

Thank you. 🦢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions