krzysztofzablocki / Sourcery

Meta-programming for Swift, stop writing boilerplate code.
http://merowing.info
MIT License
7.58k stars 605 forks source link

Crash when regenerate changed file #1329

Closed red-beeard closed 3 weeks ago

red-beeard commented 1 month ago

I receive the error Fatal error: String index is out of bounds when using Sourcery with inline generation.

Steps to reproduce:

  1. Edit the file in Xcode.
  2. Save the file (CMD+S).
  3. Trigger file regeneration.

Regeneration does not lead to an error on subsequent attempts.

Version: 2.2.4

sourcery --config .sourcery_without_project.yml --verbose
Using configuration file at '.sourcery_without_project.yml'
Resolving configurations took 0.0075528621673583984
Scanning sources...
    loadOrParse: 0.03952503204345703
    reduce: 0.00018978118896484375
    composer: 0.002712249755859375
    total: 0.04244422912597656
Found 9 types in 7 files, 1 changed from last run.
Files changed:
/Users/red_beeard/Desktop/SourceryParsable/SourceryAutoInit/Models/Episode.swift
Loading templates...
Loaded 3 templates.
    Loading took 0.005421161651611328
Generating code...
Rendering template /Users/red_beeard/Desktop/SourceryParsable/Templates/Sourcery/AutoInitClass.stencil
    Generating AutoInitClass.stencil took 0.009504079818725586
        Processing Ranges took 0.0006799697875976562
Skipping /Users/red_beeard/Desktop/SourceryParsable/SourceryAutoInit/Models/AutoInit/AutoInitClass.generated.swift as it is empty.
Rendering template /Users/red_beeard/Desktop/SourceryParsable/Templates/Sourcery/AutoInitStruct.stencil
    Generating AutoInitStruct.stencil took 0.0031342506408691406
        Processing Ranges took 0.0008521080017089844
Swift/StringUTF16View.swift:678: Fatal error: String index is out of bounds
zsh: illegal hardware instruction  sourcery --config .sourcery_without_project.yml --verbose

This repo reproduce problem. For example:

  1. Open project
  2. Build project (sourcery should be installed in terminal)
  3. Open Episode.swift
  4. Remove one property from struct
  5. Build project or run sourcery from terminal with configuration
art-divin commented 1 month ago

👏 Wow: thank you very much @red-beeard for the reproducible!

I'll have a look once I have time, but I would also like to welcome anyone to investigate and fix this crash - willing to provide as much support as needed 🤝