public override Symbol VisitNamedType(NamedTypeSymbol type) { var originalDef = type.OriginalDefinition; if ((object)originalDef != type) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; var translatedTypeArguments = type.GetAllTypeArguments(ref useSiteDiagnostics).SelectAsArray((t, v) => new TypeWithModifiers((TypeSymbol)v.Visit(t.Type), v.VisitCustomModifiers(t.CustomModifiers)), this); var translatedOriginalDef = (NamedTypeSymbol)this.Visit(originalDef); var typeMap = new TypeMap(translatedOriginalDef.GetAllTypeParameters(), translatedTypeArguments, allowAlpha: true); return(typeMap.SubstituteNamedType(translatedOriginalDef)); } Debug.Assert(type.IsDefinition); if (type.IsAnonymousType) { return(this.Visit(AnonymousTypeManager.TranslateAnonymousTypeSymbol(type))); } return(type); }
public override Symbol VisitNamedType(NamedTypeSymbol type) { var originalDef = type.OriginalDefinition; if ((object)originalDef != type) { var discardedUseSiteInfo = CompoundUseSiteInfo <AssemblySymbol> .Discarded; var translatedTypeArguments = type.GetAllTypeArguments(ref discardedUseSiteInfo).SelectAsArray((t, v) => t.WithTypeAndModifiers((TypeSymbol)v.Visit(t.Type), v.VisitCustomModifiers(t.CustomModifiers)), this); var translatedOriginalDef = (NamedTypeSymbol)this.Visit(originalDef); var typeMap = new TypeMap(translatedOriginalDef.GetAllTypeParameters(), translatedTypeArguments, allowAlpha: true); return(typeMap.SubstituteNamedType(translatedOriginalDef)); } Debug.Assert(type.IsDefinition); if (type.IsAnonymousType) { return(this.Visit(AnonymousTypeManager.TranslateAnonymousTypeSymbol(type))); } return(type); }
public override Symbol VisitNamedType(NamedTypeSymbol type) { var originalDef = (NamedTypeSymbol)type.OriginalDefinition; if ((object)originalDef != (object)type) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; var typeArguments = type.GetAllTypeArguments(ref useSiteDiagnostics); var otherDef = (NamedTypeSymbol)this.Visit(originalDef); if ((object)otherDef == null) { return(null); } var otherTypeParameters = otherDef.GetAllTypeParameters(); var otherTypeArguments = typeArguments.SelectAsArray((t, v) => (TypeSymbol)v.Visit(t), this); Debug.Assert(otherTypeArguments.All(t => (object)t != null)); var typeMap = new TypeMap(otherTypeParameters, otherTypeArguments); return(typeMap.SubstituteNamedType(otherDef)); } Debug.Assert(type.IsDefinition); var otherContainer = this.Visit(type.ContainingSymbol); // Containing type will be missing from other assembly // if the type was added in the (newer) source assembly. if ((object)otherContainer == null) { return(null); } switch (otherContainer.Kind) { case SymbolKind.Namespace: if (AnonymousTypeManager.IsAnonymousTypeTemplate(type)) { Debug.Assert((object)otherContainer == (object)this.otherAssembly.GlobalNamespace); AnonymousTypeValue value; this.TryFindAnonymousType(type, out value); return((NamedTypeSymbol)value.Type); } else if (type.IsAnonymousType) { return(this.Visit(AnonymousTypeManager.TranslateAnonymousTypeSymbol(type))); } else { return(VisitNamespaceMembers((NamespaceSymbol)otherContainer, type, AreNamedTypesEqual)); } case SymbolKind.NamedType: return(VisitNamedTypeMembers((NamedTypeSymbol)otherContainer, type, AreNamedTypesEqual)); default: throw ExceptionUtilities.UnexpectedValue(otherContainer.Kind); } }
public override Symbol VisitNamedType(NamedTypeSymbol sourceType) { var originalDef = sourceType.OriginalDefinition; if ((object)originalDef != (object)sourceType) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; var typeArguments = sourceType.GetAllTypeArguments(ref useSiteDiagnostics); var otherDef = (NamedTypeSymbol)this.Visit(originalDef); if ((object)otherDef == null) { return(null); } var otherTypeParameters = otherDef.GetAllTypeParameters(); bool translationFailed = false; var otherTypeArguments = typeArguments.SelectAsArray((t, v) => { var newType = (TypeSymbol)v.Visit(t.Type); if ((object)newType == null) { // For a newly added type, there is no match in the previous generation, so it could be null. translationFailed = true; newType = t.Type; } return(new TypeWithModifiers(newType, v.VisitCustomModifiers(t.CustomModifiers))); }, this); if (translationFailed) { // For a newly added type, there is no match in the previous generation, so it could be null. return(null); } // TODO: LambdaFrame has alpha renamed type parameters, should we rather fix that? var typeMap = new TypeMap(otherTypeParameters, otherTypeArguments, allowAlpha: true); return(typeMap.SubstituteNamedType(otherDef)); } else if (sourceType.IsTupleType) { var otherDef = (NamedTypeSymbol)this.Visit(sourceType.TupleUnderlyingType); if ((object)otherDef == null || !otherDef.IsTupleOrCompatibleWithTupleOfCardinality(sourceType.TupleElementTypes.Length)) { return(null); } return(TupleTypeSymbol.Create(otherDef, sourceType.TupleElementNames)); } Debug.Assert(sourceType.IsDefinition); var otherContainer = this.Visit(sourceType.ContainingSymbol); // Containing type will be missing from other assembly // if the type was added in the (newer) source assembly. if ((object)otherContainer == null) { return(null); } switch (otherContainer.Kind) { case SymbolKind.Namespace: if (AnonymousTypeManager.IsAnonymousTypeTemplate(sourceType)) { Debug.Assert((object)otherContainer == (object)_otherAssembly.GlobalNamespace); AnonymousTypeValue value; this.TryFindAnonymousType(sourceType, out value); return((NamedTypeSymbol)value.Type); } else if (sourceType.IsAnonymousType) { return(this.Visit(AnonymousTypeManager.TranslateAnonymousTypeSymbol(sourceType))); } else { return(FindMatchingNamespaceMember((NamespaceSymbol)otherContainer, sourceType, AreNamedTypesEqual)); } case SymbolKind.NamedType: return(FindMatchingNamedTypeMember((NamedTypeSymbol)otherContainer, sourceType, AreNamedTypesEqual)); default: throw ExceptionUtilities.UnexpectedValue(otherContainer.Kind); } }
public override Symbol VisitNamedType(NamedTypeSymbol sourceType) { var originalDef = sourceType.OriginalDefinition; if ((object)originalDef != (object)sourceType) { var discardedUseSiteInfo = CompoundUseSiteInfo <AssemblySymbol> .Discarded; var typeArguments = sourceType.GetAllTypeArguments(ref discardedUseSiteInfo); var otherDef = (NamedTypeSymbol)Visit(originalDef); if (otherDef is null) { return(null); } var otherTypeParameters = otherDef.GetAllTypeParameters(); bool translationFailed = false; var otherTypeArguments = typeArguments.SelectAsArray((t, v) => { var newType = (TypeSymbol)v.Visit(t.Type); if (newType is null) { // For a newly added type, there is no match in the previous generation, so it could be null. translationFailed = true; newType = t.Type; } return(t.WithTypeAndModifiers(newType, v.VisitCustomModifiers(t.CustomModifiers))); }, this); if (translationFailed) { // For a newly added type, there is no match in the previous generation, so it could be null. return(null); } // TODO: LambdaFrame has alpha renamed type parameters, should we rather fix that? var typeMap = new TypeMap(otherTypeParameters, otherTypeArguments, allowAlpha: true); return(typeMap.SubstituteNamedType(otherDef)); } Debug.Assert(sourceType.IsDefinition); var otherContainer = this.Visit(sourceType.ContainingSymbol); // Containing type will be missing from other assembly // if the type was added in the (newer) source assembly. if (otherContainer is null) { return(null); } switch (otherContainer.Kind) { case SymbolKind.Namespace: if (sourceType is AnonymousTypeManager.AnonymousTypeTemplateSymbol template) { Debug.Assert((object)otherContainer == (object)_otherAssembly.GlobalNamespace); TryFindAnonymousType(template, out var value); return((NamedTypeSymbol)value.Type?.GetInternalSymbol()); } if (sourceType.IsAnonymousType) { return(Visit(AnonymousTypeManager.TranslateAnonymousTypeSymbol(sourceType))); } return(FindMatchingMember(otherContainer, sourceType, AreNamedTypesEqual)); case SymbolKind.NamedType: return(FindMatchingMember(otherContainer, sourceType, AreNamedTypesEqual)); default: throw ExceptionUtilities.UnexpectedValue(otherContainer.Kind); } }