[SR-2690] Bad code generated for FileManager.enumerator(at:includingPropertiesForKeys:options:errorHandler:) #45295
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Additional Detail from JIRA
md5: 2cb02e6b428903f7d8079ad01987a3e2
is duplicated by:
Issue Description:
If you call FileManager.enumerator(at:includingPropertiesForKeys:options:errorHandler:) with either a nonexistent directory or a symlink, and then try to iterate through the enumerator using FastEnumeration, you get a crash like this:
thread #1: tid = 0x6c49d, 0x0000000104e17d55 libswiftFoundation.dylib`static Foundation.DateComponents.unconditionallyBridgeFromObjectiveC (Swift.Optional<_ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 85, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x0000000104e17d55 libswiftFoundation.dylib`static Foundation.DateComponents.unconditionallyBridgeFromObjectiveC (Swift.Optional<_ObjC.NSDateComponents>) -> Foundation.DateComponents with unmangled suffix "_merged" + 85
frame #1: 0x000000010f57426b SwinvestigationsTests`thunk + 59 at FileManagerTests.swift:0
frame #2: 0x000000010267534c Foundation`-[NSURLDirectoryEnumerator nextObject] + 101
frame #3: 0x0000000105659645 CoreFoundation`-[NSEnumerator countByEnumeratingWithState:objects:count:] + 53
frame #4: 0x0000000104e50e89 libswiftFoundation.dylib`function signature specialization <Arg[1] = Owned To Guaranteed> of Foundation.NSFastEnumerationIterator.(refresh () -> ()).(closure #1) + 153
frame #5: 0x0000000104de3334 libswiftFoundation.dylib`Foundation.NSFastEnumerationIterator.next () -> Swift.Optional<Any> + 164
I would expect it to return nil for the optional enumerator, but it does not. The equivalent code in Objective-C works.
You can find a code example here: https://github.com/hexdreamer/Swinvestigations/blob/master/SwinvestigationsTests/FileManagerTests.swift
And the Objective-C version here: https://github.com/hexdreamer/Swinvestigations/blob/master/SwinvestigationsTests/NSFileManagerTests.m
The text was updated successfully, but these errors were encountered: