@@ -67,7 +67,7 @@ public IBoundExpression Resolve()
67
67
IBoundExpression boundExpression = null ;
68
68
if ( _lExpressionBinding != null )
69
69
{
70
- _lExpression = _lExpressionBinding . Resolve ( ) ;
70
+ _lExpression = _lExpressionBinding . Resolve ( ) ;
71
71
}
72
72
if ( _lExpression . Classification == ExpressionClassification . ResolutionFailed )
73
73
{
@@ -98,9 +98,7 @@ public IBoundExpression Resolve()
98
98
{
99
99
return boundExpression ;
100
100
}
101
- var failedExpr = new ResolutionFailedExpression ( ) ;
102
- failedExpr . AddSuccessfullyResolvedExpression ( _lExpression ) ;
103
- return failedExpr ;
101
+ return CreateFailedExpression ( _lExpression ) ;
104
102
}
105
103
106
104
private IBoundExpression ResolveLExpressionIsVariablePropertyOrFunction ( )
@@ -133,6 +131,13 @@ expression is classified as an unbound member and has a declared type of Variant
133
131
return null ;
134
132
}
135
133
var lExpressionDeclaration = _lExpression . ReferencedDeclaration ;
134
+ // The referenced declaration being null might mean that an index expression (e.g. an array with Variant elements) is used in a member access expression.
135
+ // If it's an assignment for example we still have to bind the array (and not the element's referenced declaration) thus have to return the rest of the tree.
136
+ // TODO: Find a better way of dealing with this, perhaps create declarations for Variant, Object etc.
137
+ if ( _lExpression . ReferencedDeclaration == null )
138
+ {
139
+ return new MemberAccessExpression ( null , ExpressionClassification . Unbound , _context , _unrestrictedNameContext , _lExpression ) ;
140
+ }
136
141
var referencedType = lExpressionDeclaration . AsTypeDeclaration ;
137
142
if ( referencedType == null )
138
143
{
@@ -145,31 +150,37 @@ expression is classified as an unbound member and has a declared type of Variant
145
150
var udtMember = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , referencedType , _name , DeclarationType . UserDefinedTypeMember ) ;
146
151
if ( udtMember != null )
147
152
{
148
- return new MemberAccessExpression ( udtMember , ExpressionClassification . Variable , _context , _unrestrictedNameContext , _lExpression ) ;
153
+ return new MemberAccessExpression ( udtMember , ExpressionClassification . Variable , _context , _unrestrictedNameContext , _lExpression ) ;
149
154
}
150
155
var variable = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , referencedType , _name , DeclarationType . Variable ) ;
151
156
if ( variable != null )
152
157
{
153
- return new MemberAccessExpression ( variable , ExpressionClassification . Variable , _context , _unrestrictedNameContext , _lExpression ) ;
158
+ return new MemberAccessExpression ( variable , ExpressionClassification . Variable , _context , _unrestrictedNameContext , _lExpression ) ;
154
159
}
155
160
var property = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , referencedType , _name , _propertySearchType ) ;
156
161
if ( property != null )
157
162
{
158
- return new MemberAccessExpression ( property , ExpressionClassification . Property , _context , _unrestrictedNameContext , _lExpression ) ;
163
+ return new MemberAccessExpression ( property , ExpressionClassification . Property , _context , _unrestrictedNameContext , _lExpression ) ;
159
164
}
160
165
var function = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , referencedType , _name , DeclarationType . Function ) ;
161
166
if ( function != null )
162
167
{
163
- return new MemberAccessExpression ( function , ExpressionClassification . Function , _context , _unrestrictedNameContext , _lExpression ) ;
168
+ return new MemberAccessExpression ( function , ExpressionClassification . Function , _context , _unrestrictedNameContext , _lExpression ) ;
164
169
}
165
170
var subroutine = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , referencedType , _name , DeclarationType . Procedure ) ;
166
171
if ( subroutine != null )
167
172
{
168
- return new MemberAccessExpression ( subroutine , ExpressionClassification . Subroutine , _context , _unrestrictedNameContext , _lExpression ) ;
173
+ return new MemberAccessExpression ( subroutine , ExpressionClassification . Subroutine , _context , _unrestrictedNameContext , _lExpression ) ;
169
174
}
170
- // Note: To not have to deal with declared types we simply assume that no match means unbound member.
171
- // This way the rest of the member access expression can still be bound.
172
- return new MemberAccessExpression ( null , ExpressionClassification . Unbound , _context , _unrestrictedNameContext , _lExpression ) ;
175
+ // Assume that no match = failure on our side.
176
+ return CreateFailedExpression ( _lExpression ) ;
177
+ }
178
+
179
+ private IBoundExpression CreateFailedExpression ( IBoundExpression expression )
180
+ {
181
+ var failedExpr = new ResolutionFailedExpression ( ) ;
182
+ failedExpr . AddSuccessfullyResolvedExpression ( expression ) ;
183
+ return failedExpr ;
173
184
}
174
185
175
186
private IBoundExpression ResolveLExpressionIsUnbound ( )
@@ -178,7 +189,7 @@ private IBoundExpression ResolveLExpressionIsUnbound()
178
189
{
179
190
return null ;
180
191
}
181
- return new MemberAccessExpression ( null , ExpressionClassification . Unbound , _context , _unrestrictedNameContext , _lExpression ) ;
192
+ return new MemberAccessExpression ( null , ExpressionClassification . Unbound , _context , _unrestrictedNameContext , _lExpression ) ;
182
193
}
183
194
184
195
private IBoundExpression ResolveLExpressionIsProject ( )
@@ -269,12 +280,12 @@ private IBoundExpression ResolveProject()
269
280
{
270
281
if ( _declarationFinder . IsMatch ( _project . ProjectName , _name ) )
271
282
{
272
- return new MemberAccessExpression ( _project , ExpressionClassification . Project , _context , _unrestrictedNameContext , _lExpression ) ;
283
+ return new MemberAccessExpression ( _project , ExpressionClassification . Project , _context , _unrestrictedNameContext , _lExpression ) ;
273
284
}
274
285
var referencedProjectRightOfDot = _declarationFinder . FindReferencedProject ( _project , _name ) ;
275
286
if ( referencedProjectRightOfDot != null )
276
287
{
277
- return new MemberAccessExpression ( referencedProjectRightOfDot , ExpressionClassification . Project , _context , _unrestrictedNameContext , _lExpression ) ;
288
+ return new MemberAccessExpression ( referencedProjectRightOfDot , ExpressionClassification . Project , _context , _unrestrictedNameContext , _lExpression ) ;
278
289
}
279
290
return null ;
280
291
}
@@ -285,20 +296,20 @@ private IBoundExpression ResolveProceduralModule(bool lExpressionIsEnclosingProj
285
296
{
286
297
if ( _module . DeclarationType == DeclarationType . ProceduralModule && _declarationFinder . IsMatch ( _module . IdentifierName , _name ) )
287
298
{
288
- return new MemberAccessExpression ( _module , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
299
+ return new MemberAccessExpression ( _module , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
289
300
}
290
301
var proceduralModuleEnclosingProject = _declarationFinder . FindModuleEnclosingProjectWithoutEnclosingModule ( _project , _module , _name , DeclarationType . ProceduralModule ) ;
291
302
if ( proceduralModuleEnclosingProject != null )
292
303
{
293
- return new MemberAccessExpression ( proceduralModuleEnclosingProject , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
304
+ return new MemberAccessExpression ( proceduralModuleEnclosingProject , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
294
305
}
295
306
}
296
307
else
297
308
{
298
309
var proceduralModuleInReferencedProject = _declarationFinder . FindModuleReferencedProject ( _project , _module , referencedProject , _name , DeclarationType . ProceduralModule ) ;
299
310
if ( proceduralModuleInReferencedProject != null )
300
311
{
301
- return new MemberAccessExpression ( proceduralModuleInReferencedProject , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
312
+ return new MemberAccessExpression ( proceduralModuleInReferencedProject , ExpressionClassification . ProceduralModule , _context , _unrestrictedNameContext , _lExpression ) ;
302
313
}
303
314
}
304
315
return null ;
@@ -332,20 +343,20 @@ private IBoundExpression ResolveMemberInReferencedProject(bool lExpressionIsEncl
332
343
var foundType = _declarationFinder . FindMemberEnclosingModule ( _module , _parent , _name , memberType ) ;
333
344
if ( foundType != null )
334
345
{
335
- return new MemberAccessExpression ( foundType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
346
+ return new MemberAccessExpression ( foundType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
336
347
}
337
348
var accessibleType = _declarationFinder . FindMemberEnclosedProjectWithoutEnclosingModule ( _project , _module , _parent , _name , memberType ) ;
338
349
if ( accessibleType != null )
339
350
{
340
- return new MemberAccessExpression ( accessibleType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
351
+ return new MemberAccessExpression ( accessibleType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
341
352
}
342
353
}
343
354
else
344
355
{
345
356
var referencedProjectType = _declarationFinder . FindMemberReferencedProject ( _project , _module , _parent , referencedProject , _name , memberType ) ;
346
357
if ( referencedProjectType != null )
347
358
{
348
- return new MemberAccessExpression ( referencedProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
359
+ return new MemberAccessExpression ( referencedProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
349
360
}
350
361
}
351
362
return null ;
@@ -415,12 +426,12 @@ private IBoundExpression ResolveMemberInModule(Declaration module, DeclarationTy
415
426
var enclosingProjectType = _declarationFinder . FindMemberEnclosedProjectInModule ( _project , _module , _parent , module , _name , memberType ) ;
416
427
if ( enclosingProjectType != null )
417
428
{
418
- return new MemberAccessExpression ( enclosingProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
429
+ return new MemberAccessExpression ( enclosingProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
419
430
}
420
431
var referencedProjectType = _declarationFinder . FindMemberReferencedProjectInModule ( _project , _module , _parent , module , _name , memberType ) ;
421
432
if ( referencedProjectType != null )
422
433
{
423
- return new MemberAccessExpression ( referencedProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
434
+ return new MemberAccessExpression ( referencedProjectType , classification , _context , _unrestrictedNameContext , _lExpression ) ;
424
435
}
425
436
return null ;
426
437
}
@@ -439,7 +450,7 @@ as a value with the same declared type as the enum member.
439
450
var enumMember = _declarationFinder . FindMemberWithParent ( _project , _module , _parent , _lExpression . ReferencedDeclaration , _name , DeclarationType . EnumerationMember ) ;
440
451
if ( enumMember != null )
441
452
{
442
- return new MemberAccessExpression ( enumMember , ExpressionClassification . Value , _context , _unrestrictedNameContext , _lExpression ) ;
453
+ return new MemberAccessExpression ( enumMember , ExpressionClassification . Value , _context , _unrestrictedNameContext , _lExpression ) ;
443
454
}
444
455
return null ;
445
456
}
0 commit comments