public override void LookupSymbolsInSingleBinder(LookupResult result, LookupConstraints constraints) { Debug.Assert(result.IsClear); if (IsSubmission) { this.LookupMembersInternal(result, constraints.WithQualifier(_container)); return; } var imports = GetImports(constraints.BasesBeingResolved); // first lookup members of the namespace if ((constraints.Options & LookupOptions.NamespaceAliasesOnly) == 0 && _container != null) { this.LookupMembersInternal(result, constraints.WithQualifier(_container)); if (result.IsMultiViable) { // symbols cannot conflict with using alias names if (constraints.MetadataName == constraints.Name && imports.IsUsingAlias(constraints.Name, constraints.OriginalBinder.IsSemanticModelBinder)) { LanguageDiagnosticInfo diagInfo = new LanguageDiagnosticInfo(InternalErrorCode.ERR_ConflictAliasAndMember, constraints.Name, _container); var error = new ExtendedErrorTypeSymbol((NamespaceOrTypeSymbol)null, constraints.Name, constraints.MetadataName, diagInfo, unreported: true); result.SetFrom(LookupResult.Good(error)); // force lookup to be done w/ error symbol as result } return; } } // next try using aliases or symbols in imported namespaces imports.LookupSymbol(result, constraints); }
private LookupResult MemberLookupInNamespace(NamespaceSymbol ns, string name, int arity) { LookupResult result = new LookupResult(); IEnumerable <Symbol> members = ns.GetMembers(name); foreach (Symbol member in members) { LookupResult resultOfThisMember; DiagnosticInfo diagInfo; if (WrongArity(member, arity, out diagInfo)) { resultOfThisMember = LookupResult.WrongArity(member, diagInfo); } else if (!IsMemberAccessible(member)) { resultOfThisMember = LookupResult.Inaccessible(member); } else { resultOfThisMember = LookupResult.Good(member); } result = MergeLookupsInSameScope(result, resultOfThisMember); } return(result); }
private static LookupResult Resolve(IEnumerable <DeclarationReference> symbols, Package fromPackage) { var symbolsList = symbols.ToList(); var visible = symbolsList.Where(r => r.IsVisibleFrom(fromPackage)).ToList(); if (visible.Count == 1) { return(LookupResult.Good(visible.Single())); } var visibleInPackage = visible.Where(r => r.IsIn(fromPackage)).ToList(); if (visibleInPackage.Count == 1) { return(LookupResult.Good(visibleInPackage.Single())); // TODO issue warning that we have chosen the one in the current package } if (visibleInPackage.Count > 1 || visible.Count > 1) { return(LookupResult.Ambiguous(visible)); } // Nothing visible in package if (symbolsList.Count > 0) { return(LookupResult.NotAccessible(symbolsList)); } return(LookupResult.NotDefined()); }
// Given two looksup in two scopes, whereby viable results in resultHiding should hide results // in resultHidden, merge the lookups. private LookupResult MergeHidingLookups(LookupResult resultHiding, LookupResult resultHidden) { // Methods hide non-methods, non-methods hide everything. We do not implement hiding by signature // here; that can be handled later in overload lookup. Doing this efficiently is a little complex... if (resultHiding.IsViable && resultHidden.IsViable) { if (resultHiding.IsSingleton) { if (resultHiding.SingleSymbol.Kind != SymbolKind.Method) { return(resultHiding); } } else { foreach (Symbol sym in resultHiding.Symbols) { if (sym.Kind != SymbolKind.Method) { return(resultHiding); // any non-method hides everything in the hiding scope. } } } // "resultHiding" only has methods. Hide all non-methods from resultHidden. if (resultHidden.IsSingleton) { if (resultHidden.SingleSymbol.Kind == SymbolKind.Method) { return(resultHiding.MergeEqual(resultHidden)); } else { return(resultHiding); } } else { LookupResult result = resultHiding; foreach (Symbol sym in resultHidden.Symbols) { if (sym.Kind == SymbolKind.Method) { result = result.MergeEqual(LookupResult.Good(sym)); } } return(result); } } else { return(resultHiding.MergePrioritized(resultHidden)); } }
public override void LookupSymbolsInSingleBinder(LookupResult result, LookupConstraints constraints) { Debug.Assert(result.IsClear); var specialSymbol = Compilation.GetSpecialSymbol(constraints.MetadataName); if (specialSymbol.Kind != LanguageSymbolKind.ErrorType) { result.SetFrom(LookupResult.Good(specialSymbol)); } }
// Does a member lookup in a single type, without considering inheritance. private LookupResult MemberLookupWithoutInheritance(TypeSymbol type, string name, int arity, bool invoked) { LookupResult result = new LookupResult(); IEnumerable <Symbol> members = type.GetMembers(name); foreach (Symbol member in members) { LookupResult resultOfThisMember; // Do we need to exclude override members, or is that done later by overload resolution. It seems like // not excluding them here can't lead to problems, because we will always find the overridden method as well. SymbolKind memberKind = member.Kind; DiagnosticInfo diagInfo; if (WrongArity(member, arity, out diagInfo)) { resultOfThisMember = LookupResult.WrongArity(member, diagInfo); } else if (invoked && !IsInvocable(member)) { resultOfThisMember = LookupResult.Bad(member, new CSDiagnosticInfo(ErrorCode.ERR_NonInvocableMemberCalled, member.GetFullName())); } else if (!IsMemberAccessible(member)) { resultOfThisMember = LookupResult.Inaccessible(member); } else { resultOfThisMember = LookupResult.Good(member); } result = MergeLookupsInSameScope(result, resultOfThisMember); } return(result); }