Skip to content

Crash on a custom syntax file with a Swift shebang #3450

@frkd-dev

Description

@frkd-dev

Description of the problem or steps to reproduce

Preamble
The Micro has syntax support for Swift language, but only when filenames end with the .swift extension. Unfortunately, it doesn't recognize a shebang #!/usr/bin/swift and no syntax highlighting as the result. The shebang is totally valid on macOS, as that's the official Swift interpreter.

Problem
I decided to create a custom syntax file ~/.config/micro/syntax/swift.yaml with the following content:

filetype: swift
detect:
    header: "#!/usr/bin/swift"

Now, whenever I create a new file, add a shebang #!/usr/bin/swift, and then save it, the editor crashes every time with the following output:

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:261 (0x1007a381c)
runtime/signal_unix.go:861 (0x1007a37e9)
github.com/zyedidia/micro/v2/pkg/highlight/parser.go:217 (0x100b53e9d)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:775 (0x100b5d504)
github.com/zyedidia/micro/v2/internal/buffer/save.go:219 (0x100b682a4)
github.com/zyedidia/micro/v2/internal/buffer/save.go:98 (0x100b98c20)
github.com/zyedidia/micro/v2/internal/action/actions.go:829 (0x100b98bf5)
github.com/zyedidia/micro/v2/internal/action/actions.go:765 (0x100b985a0)
github.com/zyedidia/micro/v2/internal/action/actions.go:775 (0x100b9861c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:545 (0x100ba390c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:150 (0x100ba1f8c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:32 (0x100ba1d70)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:528 (0x100ba368c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:444 (0x100ba3200)
github.com/zyedidia/micro/v2/internal/action/tab.go:269 (0x100bb1e3c)
github.com/zyedidia/micro/v2/internal/action/tab.go:139 (0x100bb13e8)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:476 (0x100be8714)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:394 (0x100be7f98)
runtime/internal/atomic/types.go:194 (0x10078e15c)
runtime/asm_arm64.s:1197 (0x1007c0f04)

If I open an already existing file with the same shebang, I get a crash with the following output:

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:261 (0x104e9b81c)
runtime/signal_unix.go:861 (0x104e9b7e9)
github.com/zyedidia/micro/v2/pkg/highlight/parser.go:217 (0x10524be9d)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:775 (0x105255504)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:392 (0x105253088)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:261 (0x105251f20)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:203 (0x1052df474)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:331 (0x1052dfc10)
runtime/internal/atomic/types.go:194 (0x104e8615c)
runtime/asm_arm64.s:1197 (0x104eb8f04)

Both stacktraces are pointing at this line.

Specifications

The micro is installed using macports.

Version: 2.0.13
Commit hash: unknown
Compiled on January 12, 2024

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions