File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+ struct S {
2
+ var _x : Int
3
+ public var xImmutablePublic : Int {
4
+ @storageRestrictions ( initializes: _x)
5
+ init {
6
+ _x = initialValue
7
+ }
8
+ get {
9
+ return _x
10
+ }
11
+ }
12
+
13
+ public var xMutablePublic : Int {
14
+ @storageRestrictions ( initializes: _x)
15
+ init {
16
+ _x = initialValue
17
+ }
18
+ get {
19
+ return _x
20
+ }
21
+ set {
22
+ _x = newValue
23
+ }
24
+ }
25
+
26
+ internal var xImmutableInternal : Int {
27
+ @storageRestrictions ( initializes: _x)
28
+ init {
29
+ _x = initialValue
30
+ }
31
+ get {
32
+ return _x
33
+ }
34
+ }
35
+
36
+ internal var xMutableInternal : Int {
37
+ @storageRestrictions ( initializes: _x)
38
+ init {
39
+ _x = initialValue
40
+ }
41
+ get {
42
+ return _x
43
+ }
44
+ set {
45
+ _x = newValue
46
+ }
47
+ }
48
+ }
Original file line number Diff line number Diff line change @@ -690,3 +690,19 @@ do {
690
690
_ = Test2 ( q: " some question " ) // Ok `a` is default initialized to `nil`
691
691
_ = Test2 ( q: " ultimate question " , a: 42 )
692
692
}
693
+
694
+ struct Test2ForExtension {
695
+ var _x : Int
696
+ }
697
+
698
+ extension Test2ForExtension {
699
+ var extendedX : Int {
700
+ @storageRestrictions ( initializes: _x)
701
+ init {
702
+ // expected-error@-1 {{init accessors could only be declared in the primary declaration}}
703
+ self . _x = newValue
704
+ }
705
+ get { _x }
706
+ set { _x = newValue }
707
+ }
708
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-swift-frontend %s -verify -O -primary-file %s %S/Inputs/imported_init_accessor.swift -c -o %t/init_accessors_multi_file.o
3
+
4
+ extension S {
5
+ init ( extendedX: Int ) {
6
+ self . xImmutablePublic = extendedX
7
+ }
8
+ }
9
+
10
+ func test( ) {
11
+ let s = S ( extendedX: 42 )
12
+ _ = s. xImmutablePublic
13
+ }
You can’t perform that action at this time.
0 commit comments