forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DictionaryUnchecked.swift
39 lines (31 loc) · 1 KB
/
DictionaryUnchecked.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// RUN: mkdir -p %t
// RUN: %target-build-swift %s -o %t/a.out -Ounchecked
//
// RUN: %target-run %t/a.out
// REQUIRES: executable_test
import StdlibUnittest
// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
#if _runtime(_ObjC)
import ObjectiveC
#endif
var DictionaryUnchecked = TestSuite("DictionaryUnchecked")
DictionaryUnchecked.test("noCseOnInit") {
@inline(never)
func createDict() -> Dictionary<Int, Bool> {
// CSE should not be able to combine both Dictionary.init() calls.
// This did happen and resulted in a crash because Dictionary.init()
// was defined with @effects(readnone).
// But this was wrong because it actually reads the array buffer (from
// the literal).
var Dict: Dictionary<Int, Bool> = [:]
Dict = [:]
Dict[0] = true
return Dict
}
let Dict = createDict()
expectTrue(Dict[0]!)
}
runAllTests()