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

[SR-11364] enum formatter with optionSet doesn't show the right value #4559

Closed
swift-ci opened this issue Aug 23, 2019 · 7 comments
Closed
Labels
bug Something isn't working Compiler LLDB for Swift

Comments

@swift-ci
Copy link

Previous ID SR-11364
Radar None
Original Reporter fstaine (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.4) on macOS

Additional Detail from JIRA
Votes 0
Component/s Compiler, LLDB for Swift
Labels Bug, debuginfo
Assignee None
Priority Medium

md5: 50ebfd3bc8a3f60125a929a6d24339aa

Issue Description:

When creating an enum with an optionSet associated value, changes on the enum variable are not reflected to the varaiable.

struct OptSet: OptionSet {
    public typealias RawValue = UInt32
    
    var rawValue: UInt32
    
    static let v1 = OptSet(rawValue: 1)
    static let v2 = OptSet(rawValue:2)
}

enum Test {
    case t1
    case t2(OptSet)
    case t3
}

var t: Test = .t1

When changing the value to `t3` the value remains at `t1`

> t = .t3
> t
$R2: Test = t1

The value will still be `t1`.

It's not the case if the associated value doesn't extend the `OptionSet`.

@belkadan
Copy link

Looks like the runtime gets this right if you call print, so it's something wrong with how LLDB is interpreting the value. cc @dcci

@dcci
Copy link
Mannequin

dcci mannequin commented Aug 23, 2019

I'll look in an hour or such.

@dcci
Copy link
Mannequin

dcci mannequin commented Aug 23, 2019

@adrian-prantl friss (JIRA User) and I discussed this in the past several times. Unfortunately modifying values for swift types is something that didn't really get a lot of attention, so if it works, it's not really by design. We're receiving more reports about this, so we might reconsider whether we want to spend some time to modify the compiler (and lldb) to do the right thing, but I'm afraid there's nothing planned yet.

@dcci
Copy link
Mannequin

dcci mannequin commented Aug 23, 2019

We could prevent reassignment to happen in swift [and just emit an error], as they only work in few cases today. Investigating how to fix the problem in the compiler is a major undertaking and probably involves many changes to code generation (IRGen et similia).

@belkadan
Copy link

Wait, what do you mean by "modifying values for swift types"? This is a plain old var getting a new value; it's not shadowing an existing value.

@dcci
Copy link
Mannequin

dcci mannequin commented Aug 23, 2019

I need more coffee, sorry. Let me look at this again. I changed the enum code so there are chances this got fixed in 5.1, but I need to double check.

@dcci
Copy link
Mannequin

dcci mannequin commented Aug 23, 2019

Yes, this is fixed in ToT. Please re-try with a nightly snapshot. It was a bug in computing the enum layout.

  1> struct OptSet: OptionSet { 
  2.     public typealias RawValue = UInt32 
  3.      
  4.     var rawValue: UInt32 
  5.      
  6.     static let v1 = OptSet(rawValue: 1) 
  7.     static let v2 = OptSet(rawValue:2) 
  8. } 
  9.  
 10. enum Test { 
 11.     case t1 
 12.     case t2(OptSet) 
 13.     case t3 
 14. } 
 15.  
 16. var t: Test = .t1
t: Test = t1
 17> t = .t3
 18> t
$R0: Test = t3

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Compiler LLDB for Swift
Projects
None yet
Development

No branches or pull requests

2 participants