Skip to content

Commit ee0ccd1

Browse files
committed
sf.net # 1009: fbc: property byref parsing
- Invalid symbol when accessing indexed PROPERTY arrays BYREF - parser was ending on the first property index expression - if property array index is followed by member access, then continuing parsing for the next member access
1 parent e800540 commit ee0ccd1

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Version 1.20.0
9999
- gas64: fix casting ulong (with "negative value") to double/single (SARG)
100100
- gas64: fix optimization prevented converting 32bit memory/register (SARG)
101101
- fbc: #cmdline "-end" was not resetting the parser, hiding errors and producing a bad executable
102+
- sf.net #1009: Invalid symbol when accessing indexed PROPERTY arrays BYREF
102103

103104

104105
Version 1.10.3

src/compiler/parser-proccall.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ function cProcCall _
302302
end if
303303
end if
304304

305+
'' ( '.' | '->' )? then assume is getter in the right hand side expression
306+
select case lexGetToken()
307+
case CHAR_DOT, FB_TK_FIELDDEREF
308+
options or= FB_PARSEROPT_OPTONLY
309+
end select
310+
305311
'' it's a property get call being deref'd or discarded
306312
end if
307313

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#include "fbcunit.bi"
2+
3+
SUITE( fbc_tests.structs.obj_property_idx_byref )
4+
5+
type A
6+
num as integer
7+
end type
8+
9+
type B
10+
num as integer
11+
declare property p( byval index as long ) byref as A
12+
end type
13+
14+
type C
15+
num as integer
16+
declare property p( byval index as long ) byref as A
17+
declare property p( byval index as long, byref value as A )
18+
end type
19+
20+
type D
21+
num as integer
22+
declare property q( byval index as long ) byref as C
23+
declare property q( byval index as long, byref value as C )
24+
end type
25+
26+
dim shared g0A as A = ( 10 )
27+
dim shared g0B as B = ( 20 )
28+
dim shared g0C as C = ( 30 )
29+
dim shared g0D as D = ( 40 )
30+
31+
dim shared g1A as A = ( 11 )
32+
dim shared g1B as B = ( 21 )
33+
dim shared g1C as C = ( 31 )
34+
dim shared g1D as D = ( 41 )
35+
36+
property B.p( byval index as long ) byref as A
37+
if( index = 0 ) then
38+
return g0A
39+
end if
40+
return g1A
41+
end property
42+
43+
property C.p( byval index as long ) byref as A
44+
if( index = 0 ) then
45+
return g0A
46+
end if
47+
return g1A
48+
end property
49+
50+
property C.p( byval index as long, byref value as A )
51+
if( index = 0 ) then
52+
g0A = value
53+
return
54+
end if
55+
g1A = value
56+
end property
57+
58+
property D.q( byval index as long ) byref as C
59+
if( index = 0 ) then
60+
return g0C
61+
end if
62+
return g1C
63+
end property
64+
65+
property D.q( byval index as long, byref value as C )
66+
if( index = 0 ) then
67+
g0C = value
68+
return
69+
end if
70+
g1C = value
71+
end property
72+
73+
TEST( all )
74+
75+
dim w0 as A = ( 100 )
76+
dim x0 as B = ( 200 )
77+
dim y0 as C = ( 300 )
78+
dim z0 as D = ( 400 )
79+
80+
CU_ASSERT( w0.num = 100 )
81+
82+
CU_ASSERT( x0.num = 200 )
83+
CU_ASSERT( x0.p(0).num = 10 )
84+
CU_ASSERT( x0.p(1).num = 11 )
85+
86+
CU_ASSERT( y0.num = 300 )
87+
CU_ASSERT( y0.p(0).num = 10 )
88+
CU_ASSERT( y0.p(1).num = 11 )
89+
90+
CU_ASSERT( z0.num = 400 )
91+
CU_ASSERT( z0.q(0).p(0).num = 10 )
92+
CU_ASSERT( z0.q(0).p(1).num = 11 )
93+
CU_ASSERT( z0.q(1).p(0).num = 10 )
94+
CU_ASSERT( z0.q(1).p(1).num = 11 )
95+
96+
dim w1 as A = ( 101 )
97+
98+
y0.p(0) = w1
99+
100+
CU_ASSERT( y0.num = 300 )
101+
CU_ASSERT( y0.p(0).num = 101 )
102+
CU_ASSERT( y0.p(1).num = 11 )
103+
104+
CU_ASSERT( z0.num = 400 )
105+
CU_ASSERT( z0.q(0).p(0).num = 101 )
106+
CU_ASSERT( z0.q(0).p(1).num = 11 )
107+
CU_ASSERT( z0.q(1).p(0).num = 101 )
108+
CU_ASSERT( z0.q(1).p(1).num = 11 )
109+
110+
dim w2 as A = ( 102 )
111+
112+
y0.p(1).num = w2.num
113+
114+
CU_ASSERT( y0.num = 300 )
115+
CU_ASSERT( y0.p(0).num = 101 )
116+
CU_ASSERT( y0.p(1).num = 102 )
117+
118+
CU_ASSERT( z0.num = 400 )
119+
CU_ASSERT( z0.q(0).p(0).num = 101 )
120+
CU_ASSERT( z0.q(0).p(1).num = 102 )
121+
CU_ASSERT( z0.q(1).p(0).num = 101 )
122+
CU_ASSERT( z0.q(1).p(1).num = 102 )
123+
124+
dim y1 as C = ( 301 )
125+
126+
z0.q(0) = y1
127+
128+
CU_ASSERT( y0.num = 300 )
129+
CU_ASSERT( y0.p(0).num = 101 )
130+
CU_ASSERT( y0.p(1).num = 102 )
131+
132+
CU_ASSERT( z0.num = 400 )
133+
CU_ASSERT( z0.q(0).p(0).num = 101 )
134+
CU_ASSERT( z0.q(0).p(1).num = 102 )
135+
CU_ASSERT( z0.q(1).p(0).num = 101 )
136+
CU_ASSERT( z0.q(1).p(1).num = 102 )
137+
138+
dim y2 as C = ( 302 )
139+
140+
z0.q(0).num = y2.num
141+
142+
CU_ASSERT( y0.num = 300 )
143+
CU_ASSERT( y0.p(0).num = 101 )
144+
CU_ASSERT( y0.p(1).num = 102 )
145+
146+
CU_ASSERT( z0.num = 400 )
147+
CU_ASSERT( z0.q(0).p(0).num = 101 )
148+
CU_ASSERT( z0.q(0).p(1).num = 102 )
149+
CU_ASSERT( z0.q(1).p(0).num = 101 )
150+
CU_ASSERT( z0.q(1).p(1).num = 102 )
151+
152+
153+
dim w3 as A = ( 103 )
154+
155+
z0.q(0).p(0) = w3
156+
157+
CU_ASSERT( z0.num = 400 )
158+
CU_ASSERT( z0.q(0).p(0).num = 103 )
159+
CU_ASSERT( z0.q(0).p(1).num = 102 )
160+
CU_ASSERT( z0.q(1).p(0).num = 103 )
161+
CU_ASSERT( z0.q(1).p(1).num = 102 )
162+
163+
END_TEST
164+
165+
END_SUITE

0 commit comments

Comments
 (0)