Files
swift-mirror/test/SILOptimizer/moveonly_lazy_initialized_globals.swift
Michael Gottesman 1f22f92170 [move-only] Fix lazily initialized global initializers.
Without this, we emit a copy of noncopyable type error since we do not insert a
mark_must_check on lazily initialized global initializers.

rdar://111402912
2023-07-17 19:17:43 -07:00

35 lines
604 B
Swift

// RUN: %target-swift-emit-sil -sil-verify-all -parse-as-library -verify %s
struct S: ~Copyable {
let s: String
init(_ s: String) { self.s = s }
deinit { print("deiniting \(s)") }
}
struct M4 : ~Copyable {
var s1: S
var s2: S
init(_ s: String) {
fatalError()
}
}
func rewriteTwo(_ one: inout S, _ two: inout S) {
one = S("new1")
two = S("new2")
}
var m = M4("1")
var m2 = M4("1")
struct Doit {
static var m3 = M4("1")
static var m4 = M4("1")
// We should get no diagnostics.
static func run() {
rewriteTwo(&m.s1, &m2.s2)
rewriteTwo(&m3.s1, &m4.s2)
}
}