From d8a9c428b007339c090f9c27eaf2bde126b7cd41 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 11 Mar 2024 21:06:37 -0700 Subject: [PATCH] [Test] Add regression test. For https://github.com/apple/swift/issues/72055 . --- validation-test/SILOptimizer/gh72055.swift | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 validation-test/SILOptimizer/gh72055.swift diff --git a/validation-test/SILOptimizer/gh72055.swift b/validation-test/SILOptimizer/gh72055.swift new file mode 100644 index 0000000000000..67ca8bd23bc40 --- /dev/null +++ b/validation-test/SILOptimizer/gh72055.swift @@ -0,0 +1,52 @@ +// RUN: %target-swift-frontend -emit-sil -verify %s + +struct PinnedInfo { + var hasPinnedCells: Bool { + return !allPins.isEmpty + } + + var allPins: ContiguousArray + + init(allPins: ContiguousArray = []) { + self.allPins = allPins + } +} + +enum ModelState: Hashable, CaseIterable { + case initial + case modified +} + +struct Storage { + var initial: Model? + var modified: Model? + + mutating func setStorage(_ storage: Model, at state: ModelState) { + switch state { + case .initial: + initial = storage + case .modified: + modified = storage + } + } +} + +func test() { + var storagePinInfo = Storage() + var storageAllPins = Storage>() + + var pinInfo = PinnedInfo(allPins: []) // expected-warning{{variable 'pinInfo' was never mutated; consider changing to 'let' constant}} + var allPins = Array(repeating: 0, count: 100) // expected-warning{{variable 'allPins' was never mutated; consider changing to 'let' constant}} + + storagePinInfo.setStorage(consume pinInfo, at: .initial) + storageAllPins.setStorage(consume allPins, at: .initial) +} + +var storagePinInfo = Storage() +var storageAllPins = Storage>() + +var pinInfo = PinnedInfo(allPins: []) +var allPins = Array(repeating: 0, count: 100) + +storagePinInfo.setStorage(consume pinInfo, at: .initial) // expected-error{{'consume' cannot be applied to globals}} +storageAllPins.setStorage(consume allPins, at: .initial) // expected-error{{'consume' cannot be applied to globals}}