aboutsummaryrefslogtreecommitdiff
path: root/test/SemaObjC/property-user-setter.m
blob: e84fad2394aba96183919866fbf07a07fb05d891 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s

@interface I0 
@property(readonly) int x;
@property(readonly) int y;
@property(readonly) int z;
-(void) setY: (int) y0;
@end

@interface I0 (Cat0)
-(void) setX: (int) a0;
@end

@implementation I0
@dynamic x;
@dynamic y;
@dynamic z;
-(void) setY: (int) y0{}

-(void) im0 {
  self.x = 0;
  self.y = 2;
  self.z = 2; // expected-error {{assignment to readonly property}}
}
@end

// Test when property is 'readonly' but it has a setter in
// its implementation only.
@interface I1  {
}
@property(readonly) int identifier;
@end


@implementation I1
@dynamic identifier;
- (void)setIdentifier:(int)ident {}

- (id)initWithIdentifier:(int)Arg {
    self.identifier = 0;
}

@end


// Also in a category implementation
@interface I1(CAT)  
@property(readonly) int rprop;
@end


@implementation I1(CAT)
@dynamic rprop;
- (void)setRprop:(int)ident {}

- (id)initWithIdentifier:(int)Arg {
    self.rprop = 0;
}

@end

static int g_val;

@interface Root 
+ alloc;
- init;
@end

@interface Subclass : Root
{
    int setterOnly;
}
- (void) setSetterOnly:(int)value;
@end

@implementation Subclass
- (void) setSetterOnly:(int)value {
    setterOnly = value;
    g_val = setterOnly;
}
@end

@interface C {}
// - (int)Foo;
- (void)setFoo:(int)value;
@end

void g(int);

void f(C *c) {
    c.Foo = 17; // OK 
    g(c.Foo); // expected-error {{no getter method for read from property}}
}


void abort(void);
int main (void) {
    Subclass *x = [[Subclass alloc] init];

    x.setterOnly = 4;   // OK
    if (g_val != 4)
      abort ();
    return 0;
}

// rdar://11363363
@interface rdar11363363
{
  id R;
}
@property (copy) id p;
@property (copy) id r;
@property (copy) id Q;
@property (copy) id t; // expected-note 2 {{property declared here}}
@property (copy) id T; // expected-note 2 {{property declared here}}
@property (copy) id Pxyz; // expected-note 2 {{property declared here}}
@property (copy) id pxyz; // expected-note 2 {{property declared here}}
@end

@implementation rdar11363363
@synthesize p;
@synthesize r;
@synthesize Q;
@synthesize t, T;
@synthesize Pxyz, pxyz;
- (id) Meth {
  self.P = 0;
  self.q = 0;
// rdar://11528439
  self.t = 0; // expected-error {{synthesized properties 't' and 'T' both claim setter 'setT:'}}
  self.T = 0; // expected-error {{synthesized properties 'T' and 't' both claim setter 'setT:'}}
  self.Pxyz = 0; // expected-error {{synthesized properties 'Pxyz' and 'pxyz' both claim setter 'setPxyz:'}}
  self.pxyz = 0; // expected-error {{synthesized properties 'pxyz' and 'Pxyz' both claim setter 'setPxyz:'}}
  self.R = 0;
  return self.R; // expected-error {{no getter method for read from property}}
}
@end

// rdar://11499742
@class BridgeFormatter;

@interface FMXBridgeFormatter 

@property(assign, readwrite, getter=formatter, setter=setFormatter:) BridgeFormatter* cppFormatter;

@end

@implementation FMXBridgeFormatter
@synthesize cppFormatter;

- (void) dealloc
{
 self.formatter = 0;
}
@end