IsImportedTypeOverride() public static method

public static IsImportedTypeOverride ( System.TypeSpec ts, System.TypeSpec found ) : System.TypeSpec
ts System.TypeSpec
found System.TypeSpec
return System.TypeSpec
Exemplo n.º 1
0
        FullNamedExpression Lookup(string name, int arity, LookupMode mode, Location loc)
        {
            //
            // Check whether it's in the namespace.
            //
            FullNamedExpression fne = ns.LookupTypeOrNamespace(this, name, arity, mode, loc);

            //
            // Check aliases.
            //
            if (using_aliases != null && arity == 0)
            {
                foreach (NamespaceUsingAlias ue in using_aliases)
                {
                    if (ue.Alias == name)
                    {
                        if (fne != null)
                        {
                            if (Doppelganger != null)
                            {
                                if (mode == LookupMode.Normal)
                                {
                                    // TODO: Namespace has broken location
                                    //Report.SymbolRelatedToPreviousError (fne.Location, null);
                                    Compiler.Report.SymbolRelatedToPreviousError(ue.Location, null);
                                    Compiler.Report.Error(576, loc,
                                                          "Namespace `{0}' contains a definition with same name as alias `{1}'",
                                                          GetSignatureForError(), name);
                                }
                            }
                            else
                            {
                                return(fne);
                            }
                        }

                        return(ue.Resolve(Doppelganger ?? this, Doppelganger == null));
                    }
                }
            }

            if (fne != null)
            {
                return(fne);
            }

            if (IsImplicit)
            {
                return(null);
            }

            //
            // Check using entries.
            //
            FullNamedExpression match = null;

            foreach (Namespace using_ns in GetUsingTable())
            {
                // A using directive imports only types contained in the namespace, it
                // does not import any nested namespaces
                fne = using_ns.LookupType(this, name, arity, mode, loc);
                if (fne == null)
                {
                    continue;
                }

                if (match == null)
                {
                    match = fne;
                    continue;
                }

                // Prefer types over namespaces
                var texpr_fne   = fne as TypeExpr;
                var texpr_match = match as TypeExpr;
                if (texpr_fne != null && texpr_match == null)
                {
                    match = fne;
                    continue;
                }
                else if (texpr_fne == null)
                {
                    continue;
                }

                // It can be top level accessibility only
                var better = Namespace.IsImportedTypeOverride(module, texpr_match.Type, texpr_fne.Type);
                if (better == null)
                {
                    if (mode == LookupMode.Normal)
                    {
                        Compiler.Report.SymbolRelatedToPreviousError(texpr_match.Type);
                        Compiler.Report.SymbolRelatedToPreviousError(texpr_fne.Type);
                        Compiler.Report.Error(104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
                                              name, texpr_match.GetSignatureForError(), texpr_fne.GetSignatureForError());
                    }

                    return(match);
                }

                if (better == texpr_fne.Type)
                {
                    match = texpr_fne;
                }
            }

            return(match);
        }
Exemplo n.º 2
0
        private FullNamedExpression Lookup(string name, int arity, Location loc, bool ignore_cs0104)
        {
            //
            // Check whether it's in the namespace.
            //
            FullNamedExpression fne = ns.Lookup(Compiler, name, arity, loc);

            //
            // Check aliases.
            //
            if (using_aliases != null && arity == 0)
            {
                foreach (UsingAliasEntry ue in using_aliases)
                {
                    if (ue.Alias == name)
                    {
                        if (fne != null)
                        {
                            if (Doppelganger != null)
                            {
                                // TODO: Namespace has broken location
                                //Report.SymbolRelatedToPreviousError (fne.Location, null);
                                Compiler.Report.SymbolRelatedToPreviousError(ue.Location, null);
                                Compiler.Report.Error(576, loc,
                                                      "Namespace `{0}' contains a definition with same name as alias `{1}'",
                                                      GetSignatureForError(), name);
                            }
                            else
                            {
                                return(fne);
                            }
                        }

                        return(ue.Resolve(Doppelganger ?? this, Doppelganger == null));
                    }
                }
            }

            if (fne != null)
            {
                if (!((fne.Type.Modifiers & Modifiers.INTERNAL) != 0 && !fne.Type.MemberDefinition.IsInternalAsPublic(RootContext.ToplevelTypes.DeclaringAssembly)))
                {
                    return(fne);
                }
            }

            if (IsImplicit)
            {
                return(null);
            }

            //
            // Check using entries.
            //
            FullNamedExpression match = null;

            foreach (Namespace using_ns in GetUsingTable())
            {
                // A using directive imports only types contained in the namespace, it
                // does not import any nested namespaces
                fne = using_ns.LookupType(Compiler, name, arity, false, loc);
                if (fne == null)
                {
                    continue;
                }

                if (match == null)
                {
                    match = fne;
                    continue;
                }

                // Prefer types over namespaces
                var texpr_fne   = fne as TypeExpr;
                var texpr_match = match as TypeExpr;
                if (texpr_fne != null && texpr_match == null)
                {
                    match = fne;
                    continue;
                }
                else if (texpr_fne == null)
                {
                    continue;
                }

                if (ignore_cs0104)
                {
                    return(match);
                }

                // It can be top level accessibility only
                var better = Namespace.IsImportedTypeOverride(texpr_match.Type, texpr_fne.Type);
                if (better == null)
                {
                    Compiler.Report.SymbolRelatedToPreviousError(texpr_match.Type);
                    Compiler.Report.SymbolRelatedToPreviousError(texpr_fne.Type);
                    Compiler.Report.Error(104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
                                          name, texpr_match.GetSignatureForError(), texpr_fne.GetSignatureForError());
                    return(match);
                }

                if (better == texpr_fne.Type)
                {
                    match = texpr_fne;
                }
            }

            return(match);
        }