fredrikekre / Runic.jl

A code formatter for Julia with rules set in stone.
MIT License
98 stars 3 forks source link

Runic.AssertionError: `nb != span(node)` #15

Closed DanielVandH closed 3 months ago

DanielVandH commented 3 months ago

Great tool! I tried it out on DelaunayTriangulation.jl but I get an assertion error:

PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> julia -e 'using Runic; exit(Runic.main(ARGS))' -- --diff --inplace 'src/DelaunayTriangulation.jl'
Formatting `src/DelaunayTriangulation.jl` .................................... ✖
ERROR: Runic.AssertionError: `nb != span(node)`. This is unexpected, please file an issue with a reproducible example at https://github.com/fredrikekre/Runic.jl/issues/new.
Stacktrace:
 [1] trim_trailing_whitespace(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\runestone.jl:22
 [2] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:301
 [3] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233
 [4] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:325
 [5] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233
PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> 

I'm not sure I quite understand it. The contents of src/DelaunayTriangulation.jl is simply

module DelaunayTriangulation

include("setup.jl")

@static if USE_EXACTPREDICATES
    using ExactPredicates
end
using EnumX
using Random

include("data_structures.jl")
include("geometric_primitives.jl")
include("predicates.jl")
include("utils.jl")
include("algorithms.jl")
include("validation.jl")
include("exports.jl")

end

but when I put this into a new file, say test5.jl (as I was trying to do when making a smaller MWE for this issue..), everything works:

PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> julia -e 'using Runic; exit(Runic.main(ARGS))' -- --diff --inplace 'src/test5.jl'       
Formatting `src/test5.jl` .................................................... ✔
warning: in the working copy of 'a\test5.jl', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'b\test5.jl', LF will be replaced by CRLF the next time Git touches it
PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> gc src/test5.jl
module DelaunayTriangulation

include("setup.jl")

@static if USE_EXACTPREDICATES
    using ExactPredicates
end
using EnumX
using Random

include("data_structures.jl")
include("geometric_primitives.jl")
include("predicates.jl")
include("utils.jl")
include("algorithms.jl")
include("validation.jl")
include("exports.jl")

end
PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> 

Any ideas what's going wrong here? The tool works on other files in the repo like src/setup.jl, although the same error shows for src/exports.jl.

fredrikekre commented 3 months ago

Thanks for the report. Are you on windows? I think this might be fixed by https://github.com/JuliaLang/JuliaSyntax.jl/pull/455 in that case. I asked for a new release earlier (https://github.com/JuliaLang/JuliaSyntax.jl/pull/455#issuecomment-2226152012).

DanielVandH commented 3 months ago

Yeah, on Windows. I'll try it again once that's released and see.

fredrikekre commented 3 months ago

Could also be related to:

warning: in the working copy of 'a\test5.jl', LF will be replaced by CRLF the next time Git touches it

I haven't really understood how line endings are handled by git on Windows.

DanielVandH commented 3 months ago

That was just me running the test again for making the issue sorry, I should've cleared it. That shouldn't be related.

DanielVandH commented 3 months ago

Or I'm wrong and it is related sorry. Just tried it again

PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> julia -e 'using Runic; exit(Runic.main(ARGS))' -- --inplace 'src/DelaunayTriangulation.jl'
Formatting `src/DelaunayTriangulation.jl` .................................... ✖
ERROR: Runic.AssertionError: `nb != span(node)`. This is unexpected, please file an issue with a reproducible example at https://github.com/fredrikekre/Runic.jl/issues/new.
Stacktrace:
 [1] trim_trailing_whitespace(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\runestone.jl:22
 [2] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:301
 [3] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233
 [4] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:325
 [5] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233
PS C:\Users\danjv\.julia\dev\DelaunayTriangulation.jl> julia -e 'using Runic; exit(Runic.main(ARGS))' -- --inplace 'src/test12.jl'             
Formatting `src/test12.jl` ................................................... ✖
ERROR: Runic.AssertionError: `nb != span(node)`. This is unexpected, please file an issue with a reproducible example at https://github.com/fredrikekre/Runic.jl/issues/new.
Stacktrace:
 [1] trim_trailing_whitespace(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\runestone.jl:22
 [2] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:301
 [3] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233
 [4] format_node!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:325
 [5] format_node_with_kids!(ctx::Runic.Context, node::Runic.Node)
   @ Runic C:\Users\danjv\.julia\packages\Runic\pOBbp\src\Runic.jl:233

Wouldn't be the complete issue I think since it breaks on a bunch of other files in my repo that I hadn't touched with Git first (unless Git is doing weird things that I'm unaware of, which is possible).

fredrikekre commented 3 months ago

I can't reproduce this even if I change all \n to \r\n. If you still have a file where this happens can you attach the file directly so that I get the exakt file and so that not bytes are lost in the copy-pasting.