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

[Xcode 13.3] NSRangeException in ClosureEndIndentationRule.isFirstArgumentOnNewline(_:file:) #3830

Closed
2 tasks done
HeEAaD opened this issue Jan 27, 2022 · 6 comments · Fixed by #3831
Closed
2 tasks done
Labels
bug Unexpected and reproducible misbehavior.

Comments

@HeEAaD
Copy link
Contributor

HeEAaD commented Jan 27, 2022

New Issue Checklist

Describe the bug

A NSRangeException after upgrading to Xcode 13.3 beta 1:

In ClosureEndIndentationRule.isFirstArgumentOnNewline(_:file:) a range with a negative length gets passed to NSRegularExpression.firstMatch(in:options:range:):

let match = regex("\\(\\s*\\n\\s*").firstMatch(in: file.contents, options: [], range: range)?.range,

Complete output when running SwiftLint, including the stack trace and command used
$ echo "(-variable).foo()" | swiftlint lint --no-cache --use-stdin --enable-all-rules
2022-01-27 22:01:40.503 swiftlint[69553:1646431] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: Range or index out of bounds'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000188db81cc __exceptionPreprocess + 240
	1   libobjc.A.dylib                     0x0000000188b097b8 objc_exception_throw + 60
	2   Foundation                          0x0000000189c06e04 -[NSRegularExpression(NSMatching) enumerateMatchesInString:options:range:usingBlock:] + 1848
	3   Foundation                          0x0000000189c64afc -[NSRegularExpression(NSMatching) firstMatchInString:options:range:] + 188
	4   swiftlint                           0x000000010106f4a0 $s18SwiftLintFramework25ClosureEndIndentationRuleV24isFirstArgumentOnNewline33_AA5F6345B34AB3E1BF41C0044359A3D3LL_4fileSbAA22SourceKittenDictionaryV_AA0aB4FileCtFTf4nnd_nTf4xn_n + 340
	5   swiftlint                           0x000000010106fe6c $s18SwiftLintFramework25ClosureEndIndentationRuleV17validateArguments33_AA5F6345B34AB3E1BF41C0044359A3D3LL2in10dictionarySayAC9ViolationAELLVGAA0aB4FileC_AA22SourceKittenDictionaryVtFTf4nnd_nTf4nx_n + 60
	6   swiftlint                           0x0000000101070ab8 $s18SwiftLintFramework25ClosureEndIndentationRuleV10violations33_AA5F6345B34AB3E1BF41C0044359A3D3LL2in2of10dictionarySayAC9ViolationAELLVGAA0aB4FileC_AA0A14ExpressionKindOAA22SourceKittenDictionaryVtFTf4nnnd_nTf4nnx_n + 272
	7   swiftlint                           0x0000000100e7f37c $s18SwiftLintFramework22SourceKittenDictionaryV18traverseDepthFirst33_0EBA09E17623EAE379194D9431F0C722LL20collectingValuesInto0G5BlockySayxGz_AHSgACXEtlFAA25ClosureEndIndentationRuleV9Violation33_AA5F6345B34AB3E1BF41C0044359A3D3LLV_Tg504$s18ab11Framework25tuvw16V10violations33_yz35B34AB3E1BF41C0044359A3D3LL2inSayAC9x28AELLVGAA0aB4FileC_tFAISgAA22deF6VXEfU_AkA0aB4FileCTf1ncn_nTf4nxng_n + 192
	8   swiftlint                           0x000000010106e090 $s18SwiftLintFramework25ClosureEndIndentationRuleV8validate4fileSayAA14StyleViolationVGAA0aB4FileC_tF + 104
	9   swiftlint                           0x0000000100ea1efc $s18SwiftLintFramework4RulePAAE4lint33_5A5F37FCDEE0B4D78BAE05A90BA8A062LL4file7regions9benchmark7storage13configuration025superfluousDisableCommandD017compilerArgumentsAA0B6ResultAELLVSgAA0aB4FileC_SayAA6RegionVGSbAA0D7StorageCAA13ConfigurationVAA011SuperfluousuvD0VSgSaySSGtFTf4nnnndnnn_n + 516
	10  swiftlint                           0x0000000100ea1a30 $s18SwiftLintFramework15CollectedLinterV18getStyleViolations33_5A5F37FCDEE0B4D78BAE05A90BA8A062LL5using9benchmarkSayAA0G9ViolationVG_SaySS2id_Sd4timetGtAA11RuleStorageC_SbtFAA0B6ResultAELLVSgAA0W0_pXEfU0_TA + 108
	11  swiftlint                           0x0000000100ea1a80 $s18SwiftLintFramework4Rule_pAA0B6Result33_5A5F37FCDEE0B4D78BAE05A90BA8A062LLVSgIgno_AaB_pAFIegnr_TRTA + 32
	12  swiftlint                           0x0000000100e81d14 $sSa18SwiftLintFrameworkE11parallelMap9transformSayqd__Gqd__xXE_tlFADSryqd__SgGzXEfU_ySiXEfU_AA4Rule_p_AA0B6Result33_5A5F37FCDEE0B4D78BAE05A90BA8A062LLVSgTg5 + 80
	13  libswiftDispatch.dylib              0x000000019b13f300 $sSiIgy_SiIegy_TRTA + 28
	14  libswiftDispatch.dylib              0x000000019b13f32c $sSiIegy_SiIyBy_TR + 32
	15  libdispatch.dylib                   0x0000000188aaebec _dispatch_client_callout2 + 20
	16  libdispatch.dylib                   0x0000000188ac23c4 _dispatch_apply_invoke + 224
	17  libdispatch.dylib                   0x0000000188aaebac _dispatch_client_callout + 20
	18  libdispatch.dylib                   0x0000000188ac043c _dispatch_root_queue_drain + 684
	19  libdispatch.dylib                   0x0000000188ac0b58 _dispatch_worker_thread2 + 164
	20  libsystem_pthread.dylib             0x0000000188c692c8 _pthread_wqthread + 228
	21  libsystem_pthread.dylib             0x0000000188c68018 start_wqthread + 8
)
libc++abi: terminating with uncaught exception of type NSException
[1]    69552 done       echo "(-variable).foo()" | 
       69553 abort      swiftlint lint --no-cache --use-stdin --enable-all-rules

Environment

  • SwiftLint version: 0.46.2

  • Installation method used: Homebrew

  • Paste your configuration file: none. I guess rule closure_end_indentation needs to be enabled.

  • Are you using nested configurations? No.

  • Which Xcode version are you using? Xcode 13.3, Build version 13E5086k

  • Do you have a sample that shows the issue?

(-variable).foo()
@jpsim
Copy link
Collaborator

jpsim commented Jan 27, 2022

Thanks for reporting this early! Hopefully this is early enough that it can be fixed in Swift before 5.6 is officially released.

@jpsim jpsim added the bug Unexpected and reproducible misbehavior. label Jan 27, 2022
@jpsim
Copy link
Collaborator

jpsim commented Jan 27, 2022

I'm not sure if this is a bug in Swift, SourceKit or SwiftLint, but this should avoid it for now: #3831

@tonyarnold
Copy link
Contributor

Is there a schedule for when there'll be a release with this fix in it, JP? I'm hitting the crash on CI after upgrading our runners to Xcode 13.3 beta 2.

@jpsim
Copy link
Collaborator

jpsim commented Feb 22, 2022

SwiftLint doesn't have a release schedule, but I'm happy to cut a release to unblock you. I'll do that today.

Note that there are still some other known issues with Swift 5.6 beyond this though: https://github.com/realm/SwiftLint/issues?q=is%3Aissue+is%3Aopen+label%3Aswift-5.6

@jpsim
Copy link
Collaborator

jpsim commented Feb 22, 2022

@tonyarnold
Copy link
Contributor

Thanks, JP - I really appreciate you doing that! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants