Bug Swift? LLDB? Xcode?

Hi,

First time on this forum and I'm no sure if this post is in the good category. I was working on my app for macOS, trying to debug a methods when I found this.
I have a Structure on my framework like this :

import Foundation

public struct MyStruct {
    
    public var type: MyTypeEnum
    public var item: MyItem
    
    public enum MyTypeEnum {
        case a
        case b
        case utility
    }
    
    public init(type: MyTypeEnum, itemType: MyItemTypeEnum, data: Data? = nil) {
        self.type = type
        self.item = MyItem(type: itemType, data: data)
    }
    
    public struct MyItem {
        public var type: MyItemTypeEnum
        public var data: Data?
    }
    
    public enum MyItemTypeEnum {
        case itemA
        case itemB
        case utility
    }
}

When I tried to use this struct in my app and pause at breakpoint I get this :

I don't understand why the debugger print myStruct > item > type : itemA (instead of utility)
Result prints "TestOK" so I get into the if....

When I tried the same code in main.swift, I got it right :

import Foundation
import TestFmwk

let myStruct = MyStruct(type: .utility, itemType: .utility)

if myStruct.item.type == MyStruct.MyItemTypeEnum.utility {
    print("Test OK")
}
else {
    print("Error")
}

That gave me headache for the last few days when trying to debug my app... ;(
If you have any idea....
Thanks


I couldn't post this in my first message (limit new user to 1 image)

Hm. Since the running code does appear to be doing the right thing, I'd say it's an LLDB bug. @Jim_Ingham, does this look familiar, or should TheSnowFox file a new bug?

That does look like lldb's getting the value wrong. If you can make a project available that demonstrates the error, please file a bug at http://bugs.swift.org and we'll take a look.

Done,
Thanks

1 Like

Just for the record: [SR-6831] LLDB get wrong variable in an enum · Issue #4500 · apple/llvm-project · GitHub