override public void OnReferenceExpression(ReferenceExpression node) { var member = node.Entity as IAccessibleMember; if (null == member) return; if (!IsAccessible(member)) { Error(CompilerErrorFactory.UnaccessibleMember(node, member)); return; } //if member is a property we also want to check the accessor specifically var property = member as IProperty; if (null == property) return; member = node.IsTargetOfAssignment() ? property.GetSetMethod() : property.GetGetMethod(); if (!IsAccessible(member)) Error(CompilerErrorFactory.UnaccessibleMember(node, member)); }
private IEntity ResolveAmbiguousReference(ReferenceExpression node, Ambiguous candidates) { var resolved = ResolveAmbiguousReferenceByAccessibility(candidates); var accessibleCandidates = resolved as Ambiguous; if (accessibleCandidates == null || AstUtil.IsTargetOfSlicing(node) || node.IsTargetOfAssignment()) return resolved; if (accessibleCandidates.AllEntitiesAre(EntityType.Property)) return ResolveAmbiguousPropertyReference(node, accessibleCandidates, EmptyExpressionCollection); if (accessibleCandidates.AllEntitiesAre(EntityType.Method)) return ResolveAmbiguousMethodReference(node, accessibleCandidates, EmptyExpressionCollection); if (accessibleCandidates.AllEntitiesAre(EntityType.Type)) return ResolveAmbiguousTypeReference(node, accessibleCandidates); return resolved; }
private IEntity ResolveAmbiguousMethodReference(ReferenceExpression node, Ambiguous candidates, ExpressionCollection args) { //BOO-656 if (!AstUtil.IsTargetOfMethodInvocation(node) && !AstUtil.IsTargetOfSlicing(node) && !node.IsTargetOfAssignment()) { return candidates.Entities[0]; } return candidates; }
void PostProcessReferenceExpression(ReferenceExpression node) { var entity = GetEntity(node); switch (entity.EntityType) { case EntityType.Type: { BindNonGenericTypeReferenceExpressionType(node, (IType)entity); break; } case EntityType.Method: { var method = entity as IMethod; if (null != method && IsGenericMethod(method) && IsStandaloneReference(node) && !IsSubjectToGenericArgumentInference(node)) CannotInferGenericMethodArguments(node, method); break; } case EntityType.Ambiguous: { var ambiguous = (Ambiguous) entity; var resolvedEntity = ResolveAmbiguousReference(node, ambiguous); var resolvedMember = resolvedEntity as IMember; if (null != resolvedMember) { ResolveMemberInfo(node, resolvedMember); break; } if (resolvedEntity is IType) { BindNonGenericTypeReferenceExpressionType(node, (IType)resolvedEntity); break; } if (!AstUtil.IsTargetOfMethodInvocation(node) && !AstUtil.IsTargetOfSlicing(node) && !node.IsTargetOfAssignment()) { Error(node, CompilerErrorFactory.AmbiguousReference( node, node.Name, ambiguous.Entities)); } break; } case EntityType.Namespace: { if (IsStandaloneReference(node)) Error(node, CompilerErrorFactory.NamespaceIsNotAnExpression(node, entity.Name)); break; } case EntityType.Parameter: case EntityType.Local: { var local = (ILocalEntity)node.Entity; local.IsUsed = true; BindExpressionType(node, local.Type); break; } default: { if (EntityType.BuiltinFunction == entity.EntityType) { CheckBuiltinUsage(node, entity); } else { if (node.ExpressionType == null) { BindExpressionType(node, ((ITypedEntity)entity).Type); } } break; } } }