Skip to content

[SR-12618] Compiler crashes when property wrapper with autoclosure is initialized  #55062

@swift-ci

Description

@swift-ci
Previous ID SR-12618
Radar rdar://problem/62894484
Original Reporter Koninis (JIRA User)
Type Bug
Environment

Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 8fd48a17dbccfaadc96b152428b1c903

Issue Description:

The follow code crashes the compiler:

@propertyWrapper
enum Lazy<Value> {
  case uninitialized(() -> Value)
  case initialized(Value)
  init(wrappedValue: @autoclosure @escaping () -> Value) {
    self = .uninitialized(wrappedValue)
  }
  var wrappedValue: Value {
    mutating get {
      switch self {
      case .uninitialized(let initializer):
        let value = initializer()
        return value
      case .initialized(let value):
        return value
      }
    }
    set {
    }
  }
}
func getBalanceFromDataBase() -> Int {
    return 100_000
}
struct BankAccount {
    @Lazy var balance: Int
    init() {
        balance = getBalanceFromDataBase()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions