diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/ExtensionGroupingInfo.cs b/src/Compilers/CSharp/Portable/Symbols/Source/ExtensionGroupingInfo.cs index cbf3f033207df..f5d0d48a54ce4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/ExtensionGroupingInfo.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/ExtensionGroupingInfo.cs @@ -474,7 +474,7 @@ static void checkCollisions(IEnumerable extensions, Func< alreadyReportedExtensions ??= PooledHashSet.GetInstance(); if (alreadyReportedExtensions.Add(extension)) { - diagnostics.Add(ErrorCode.ERR_ExtensionBlockCollision, extension.Locations[0]); + diagnostics.Add(ErrorCode.ERR_ExtensionBlockCollision, extension.GetFirstLocation()); } } } diff --git a/src/Compilers/Core/Portable/Emit/EditAndContinue/DefinitionMap.cs b/src/Compilers/Core/Portable/Emit/EditAndContinue/DefinitionMap.cs index c9ca092ce929b..f73d3d1d18a01 100644 --- a/src/Compilers/Core/Portable/Emit/EditAndContinue/DefinitionMap.cs +++ b/src/Compilers/Core/Portable/Emit/EditAndContinue/DefinitionMap.cs @@ -353,7 +353,7 @@ protected abstract void GetStateMachineFieldMapFromMetadata( { diagnostics.Add(MessageProvider.CreateDiagnostic( MessageProvider.ERR_InvalidDebugInfo, - method.Locations.First(), + method.GetFirstLocation(), method, MetadataTokens.GetToken(methodHandle), method.ContainingAssembly, @@ -438,7 +438,7 @@ protected abstract void GetStateMachineFieldMapFromMetadata( { diagnostics.Add(MessageProvider.CreateDiagnostic( MessageProvider.ERR_InvalidDebugInfo, - method.Locations.First(), + method.GetFirstLocation(), method, MetadataTokens.GetToken(localSignature), method.ContainingAssembly, @@ -479,7 +479,7 @@ private void ReportMissingStateMachineAttribute(DiagnosticBag diagnostics, IMeth { diagnostics.Add(MessageProvider.CreateDiagnostic( MessageProvider.ERR_EncUpdateFailedMissingSymbol, - method.Locations.First(), + method.GetFirstLocation(), CodeAnalysisResources.Attribute, stateMachineAttributeFullName)); } diff --git a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs index f19b24508880e..262b4ab7ffca1 100644 --- a/src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs +++ b/src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs @@ -1453,7 +1453,7 @@ private static Location GetNamedEntityLocation(INamedEntity errorEntity) protected static Location GetSymbolLocation(ISymbolInternal symbolOpt) { - return symbolOpt != null && !symbolOpt.Locations.IsDefaultOrEmpty ? symbolOpt.Locations[0] : Location.None; + return symbolOpt?.GetFirstLocationOrNone() ?? Location.None; } internal TypeAttributes GetTypeAttributes(ITypeDefinition typeDef) diff --git a/src/Compilers/Core/Portable/Symbols/ISymbolInternal.cs b/src/Compilers/Core/Portable/Symbols/ISymbolInternal.cs index cf182eaac93f9..e1113c893513c 100644 --- a/src/Compilers/Core/Portable/Symbols/ISymbolInternal.cs +++ b/src/Compilers/Core/Portable/Symbols/ISymbolInternal.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Immutable; using System.Reflection.Metadata; using System.Threading; @@ -89,6 +90,21 @@ internal interface ISymbolInternal /// bool IsDefinition { get; } + /// + /// Similar to getting the first location from . However, this can be more efficient as + /// an intermediary array may not need to be created. This can often be advantageous for perf as most symbols + /// only have a single location, and most clients only need the first location for some purpose (like error + /// reporting). + /// + /// If the symbol has no locations. + Location GetFirstLocation(); + + /// + /// Equivalent to calling , except that if is empty this + /// will return . + /// + Location GetFirstLocationOrNone(); + /// /// Gets the locations where the symbol was originally defined, either in source or /// metadata. Some symbols (for example, partial classes) may be defined in more than one diff --git a/src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/DataFlowPass.vb b/src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/DataFlowPass.vb index 6438b888d7d88..bd6d5872427b5 100644 --- a/src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/DataFlowPass.vb +++ b/src/Compilers/VisualBasic/Portable/Analysis/FlowAnalysis/DataFlowPass.vb @@ -197,10 +197,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If Not local.IsFunctionValue AndAlso Not String.IsNullOrEmpty(local.Name) Then If _writtenVariables.Contains(local) Then If local.IsConst Then - Me.diagnostics.Add(ERRID.WRN_UnusedLocalConst, local.Locations(0), If(local.Name, "dummy")) + Me.diagnostics.Add(ERRID.WRN_UnusedLocalConst, local.GetFirstLocation(), If(local.Name, "dummy")) End If Else - Me.diagnostics.Add(ERRID.WRN_UnusedLocal, local.Locations(0), If(local.Name, "dummy")) + Me.diagnostics.Add(ERRID.WRN_UnusedLocal, local.GetFirstLocation(), If(local.Name, "dummy")) End If End If End Sub diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Conversions.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Conversions.vb index ea0d099de5abd..a599ca2aab257 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Conversions.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Conversions.vb @@ -1569,7 +1569,7 @@ DoneWithDiagnostics: If delegateParam.IsByRef OrElse delegateParam.OriginalDefinition.Type.IsTypeParameter() Then Dim restrictedType As TypeSymbol = Nothing If delegateParam.Type.IsRestrictedTypeOrArrayType(restrictedType) Then - ReportDiagnostic(diagnostics, lambda.LambdaSymbol.Parameters(delegateParam.Ordinal).Locations(0), + ReportDiagnostic(diagnostics, lambda.LambdaSymbol.Parameters(delegateParam.Ordinal).GetFirstLocation(), ERRID.ERR_RestrictedType1, restrictedType) End If End If diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder_Lambda.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder_Lambda.vb index b3bea34c78b38..065d8a10fe230 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder_Lambda.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder_Lambda.vb @@ -117,7 +117,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic unboundType, unboundParam.IsByRef, unboundParam.Syntax, - unboundParam.Locations(0)) + unboundParam.GetFirstLocation()) Next If parameters.Length <> targetSignature.ParameterTypes.Length Then @@ -142,7 +142,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic unboundType, unboundParam.IsByRef, unboundParam.Syntax, - unboundParam.Locations(0)) + unboundParam.GetFirstLocation()) Next End If diff --git a/src/Compilers/VisualBasic/Portable/Binding/ExecutableCodeBinder.vb b/src/Compilers/VisualBasic/Portable/Binding/ExecutableCodeBinder.vb index a7796f6555d9b..3b02ad22507f1 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/ExecutableCodeBinder.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/ExecutableCodeBinder.vb @@ -136,7 +136,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim bestLocation As Location = Nothing For Each symbol In labels Debug.Assert(symbol.Locations.Length = 1) - Dim sourceLocation As Location = symbol.Locations(0) + Dim sourceLocation As Location = symbol.GetFirstLocation() If bestSymbol Is Nothing OrElse Me.Compilation.CompareSourceLocations(bestLocation, sourceLocation) > 0 Then bestSymbol = symbol bestLocation = sourceLocation diff --git a/src/Compilers/VisualBasic/Portable/Compilation/ClsComplianceChecker.vb b/src/Compilers/VisualBasic/Portable/Compilation/ClsComplianceChecker.vb index e0906ae3d5b36..887027d106517 100644 --- a/src/Compilers/VisualBasic/Portable/Compilation/ClsComplianceChecker.vb +++ b/src/Compilers/VisualBasic/Portable/Compilation/ClsComplianceChecker.vb @@ -763,7 +763,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If attributeData.IsTargetAttribute(AttributeDescription.CLSCompliantAttribute) Then Dim attributeClass = attributeData.AttributeClass If attributeClass IsNot Nothing Then - _diagnostics.ReportUseSite(attributeClass, If(symbol.Locations.IsEmpty, NoLocation.Singleton, symbol.Locations(0))) + _diagnostics.ReportUseSite(attributeClass, If(symbol.Locations.IsEmpty, NoLocation.Singleton, symbol.GetFirstLocation())) End If If Not attributeData.HasErrors Then @@ -831,7 +831,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Function Private Sub AddDiagnostic(symbol As Symbol, code As ERRID, ParamArray args As Object()) - Dim location = If(symbol.Locations.IsEmpty, NoLocation.Singleton, symbol.Locations(0)) + Dim location = If(symbol.Locations.IsEmpty, NoLocation.Singleton, symbol.GetFirstLocation()) Me.AddDiagnostic(symbol, code, location, args) End Sub diff --git a/src/Compilers/VisualBasic/Portable/Compilation/DocumentationComments/DocumentationCommentCompiler.Includes.vb b/src/Compilers/VisualBasic/Portable/Compilation/DocumentationComments/DocumentationCommentCompiler.Includes.vb index 70b2dc1ceab2d..3d7aec2cf622a 100644 --- a/src/Compilers/VisualBasic/Portable/Compilation/DocumentationComments/DocumentationCommentCompiler.Includes.vb +++ b/src/Compilers/VisualBasic/Portable/Compilation/DocumentationComments/DocumentationCommentCompiler.Includes.vb @@ -664,7 +664,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' can be found by the name, just deterministically choose which one to use If symbolCommentId Is Nothing OrElse Me._compilation.CompareSourceLocations( - smallestSymbol.Locations(0), symbol.Locations(0)) > 0 Then + smallestSymbol.GetFirstLocation(), symbol.GetFirstLocation()) > 0 Then symbolCommentId = id smallestSymbol = symbol diff --git a/src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb b/src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb index 1b01238942a71..3afbf26704451 100644 --- a/src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb +++ b/src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb @@ -427,7 +427,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim sourceTypeBinder As Binder = If(method.MethodKind = MethodKind.Ordinary, Nothing, BinderBuilder.CreateBinderForType( DirectCast(method.ContainingModule, SourceModuleSymbol), - method.ContainingType.Locations(0).PossiblyEmbeddedOrMySourceTree(), + method.ContainingType.GetFirstLocation().PossiblyEmbeddedOrMySourceTree(), method.ContainingType)) ' Since embedded method bodies don't produce synthesized methods (see the assertion below) @@ -593,7 +593,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Debug.Assert(sourceTypeSymbol.Locations.Length > 0) sourceTypeBinder = BinderBuilder.CreateBinderForType( DirectCast(sourceTypeSymbol.ContainingModule, SourceModuleSymbol), - sourceTypeSymbol.Locations(0).PossiblyEmbeddedOrMySourceTree, + sourceTypeSymbol.GetFirstLocation().PossiblyEmbeddedOrMySourceTree, sourceTypeSymbol) processedStaticInitializers = New Binder.ProcessedFieldOrPropertyInitializers(Binder.BindFieldAndPropertyInitializers(sourceTypeSymbol, @@ -1165,7 +1165,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic diagnostics.Add( New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_SubNewCycle1, referencingMethod, New CompoundDiagnosticInfo(diagnosticInfos.ToArray())), - referencingMethod.Locations(0))) + referencingMethod.GetFirstLocation())) ' Rotate 'diagnosticInfos' for the next constructor If diagnosticInfos.Count > 1 Then @@ -1980,12 +1980,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' Synthesized constructor diagnostics.Add(New VBDiagnostic( ErrorFactory.ErrorInfo(ERRID.ERR_NoUniqueConstructorOnBase2, containingType, containingType.BaseTypeNoUseSiteDiagnostics), - containingType.Locations(0))) + containingType.GetFirstLocation())) Else ' Regular constructor diagnostics.Add(New VBDiagnostic( ErrorFactory.ErrorInfo(ERRID.ERR_RequiredNewCallTooMany2, defaultConstructorType, containingType), - constructor.Locations(0))) + constructor.GetFirstLocation())) End If Return candidate @@ -2007,12 +2007,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' Synthesized constructor diagnostics.Add(New VBDiagnostic( ErrorFactory.ErrorInfo(ERRID.ERR_NoConstructorOnBase2, containingType, containingType.BaseTypeNoUseSiteDiagnostics), - containingType.Locations(0))) + containingType.GetFirstLocation())) Else ' Regular constructor diagnostics.Add(New VBDiagnostic( ErrorFactory.ErrorInfo(ERRID.ERR_RequiredNewCall2, defaultConstructorType, containingType), - constructor.Locations(0))) + constructor.GetFirstLocation())) End If Else @@ -2021,7 +2021,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' in *all* cases, so changing the error location to containingType's location diagnostics.Add(New VBDiagnostic( ErrorFactory.ErrorInfo(ERRID.ERR_NoAccessibleConstructorOnBase, containingType.BaseTypeNoUseSiteDiagnostics), - containingType.Locations(0))) + containingType.GetFirstLocation())) End If End If @@ -2041,13 +2041,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' Synthesized constructor. If String.IsNullOrEmpty(data.Message) Then diagnostics.Add(If(data.IsError, ERRID.ERR_NoNonObsoleteConstructorOnBase3, ERRID.WRN_NoNonObsoleteConstructorOnBase3), - containingType.Locations(0), + containingType.GetFirstLocation(), containingType, candidate, containingType.BaseTypeNoUseSiteDiagnostics) Else diagnostics.Add(If(data.IsError, ERRID.ERR_NoNonObsoleteConstructorOnBase4, ERRID.WRN_NoNonObsoleteConstructorOnBase4), - containingType.Locations(0), + containingType.GetFirstLocation(), containingType, candidate, containingType.BaseTypeNoUseSiteDiagnostics, @@ -2057,13 +2057,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' Regular constructor. If String.IsNullOrEmpty(data.Message) Then diagnostics.Add(If(data.IsError, ERRID.ERR_RequiredNonObsoleteNewCall3, ERRID.WRN_RequiredNonObsoleteNewCall3), - constructor.Locations(0), + constructor.GetFirstLocation(), candidate, containingType.BaseTypeNoUseSiteDiagnostics, containingType) Else diagnostics.Add(If(data.IsError, ERRID.ERR_RequiredNonObsoleteNewCall4, ERRID.WRN_RequiredNonObsoleteNewCall4), - constructor.Locations(0), + constructor.GetFirstLocation(), candidate, containingType.BaseTypeNoUseSiteDiagnostics, containingType, diff --git a/src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb b/src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb index 47ff89d6a4b26..1d4d124059615 100644 --- a/src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb +++ b/src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb @@ -1596,7 +1596,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ' Global code is the entry point, ignore all other Mains. If ScriptClass IsNot Nothing Then For Each main In entryPointCandidates - diagnostics.Add(ERRID.WRN_MainIgnored, main.Locations.First(), main) + diagnostics.Add(ERRID.WRN_MainIgnored, main.GetFirstLocation(), main) Next Return ScriptClass.GetScriptEntryPoint() End If diff --git a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.vb b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.vb index 930068a8a9131..b6b207df967b1 100644 --- a/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.vb +++ b/src/Compilers/VisualBasic/Portable/Lowering/AsyncRewriter/AsyncRewriter.vb @@ -109,7 +109,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim sourceMethod = TryCast(method, SourceMethodSymbol) If sourceMethod IsNot Nothing Then Return BinderBuilder.CreateBinderForMethodBody(DirectCast(sourceMethod.ContainingModule, SourceModuleSymbol), - sourceMethod.ContainingType.Locations(0).PossiblyEmbeddedOrMySourceTree(), + sourceMethod.ContainingType.GetFirstLocation().PossiblyEmbeddedOrMySourceTree(), sourceMethod) End If diff --git a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb index c37d590d70d7d..3527965e54b44 100644 --- a/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb +++ b/src/Compilers/VisualBasic/Portable/Semantics/Operators.vb @@ -333,14 +333,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Select Case opInfo.UnaryOperatorKind Case UnaryOperatorKind.IsTrue If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_OperatorRequiresBoolReturnType1, SyntaxFacts.GetText(SyntaxKind.IsTrueKeyword)), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_OperatorRequiresBoolReturnType1, SyntaxFacts.GetText(SyntaxKind.IsTrueKeyword)), method.GetFirstLocation()) result = False Else Return False End If Case UnaryOperatorKind.IsFalse If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_OperatorRequiresBoolReturnType1, SyntaxFacts.GetText(SyntaxKind.IsFalseKeyword)), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_OperatorRequiresBoolReturnType1, SyntaxFacts.GetText(SyntaxKind.IsFalseKeyword)), method.GetFirstLocation()) result = False Else Return False @@ -361,7 +361,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_OperatorRequiresIntegerParameter1, SyntaxFacts.GetText(If(opInfo.BinaryOperatorKind = BinaryOperatorKind.LeftShift, SyntaxKind.LessThanLessThanToken, - SyntaxKind.GreaterThanGreaterThanToken))), method.Locations(0)) + SyntaxKind.GreaterThanGreaterThanToken))), method.GetFirstLocation()) result = False Else Return False @@ -388,7 +388,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If Not targetsContainingType Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(targetMismatchError, method.ContainingSymbol), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(targetMismatchError, method.ContainingSymbol), method.GetFirstLocation()) result = False Else Return False @@ -400,28 +400,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If sourceType.IsObjectType() Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionFromObject), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionFromObject), method.GetFirstLocation()) result = False Else Return False End If ElseIf targetType.IsObjectType() Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToObject), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToObject), method.GetFirstLocation()) result = False Else Return False End If ElseIf sourceType.IsInterfaceType() Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionFromInterfaceType), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionFromInterfaceType), method.GetFirstLocation()) result = False Else Return False End If ElseIf targetType.IsInterfaceType() Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToInterfaceType), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToInterfaceType), method.GetFirstLocation()) result = False Else Return False @@ -430,7 +430,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic sourceType Is targetType, sourceType.GetNullableUnderlyingTypeOrSelf() Is targetType.GetNullableUnderlyingTypeOrSelf()) Then If diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToSameType), method.Locations(0)) + diagnosticsOpt.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ConversionToSameType), method.GetFirstLocation()) result = False Else Return False @@ -441,7 +441,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If diagnosticsOpt IsNot Nothing Then diagnosticsOpt.Add(ErrorFactory.ErrorInfo(If(targetType Is method.ContainingSymbol, ERRID.ERR_ConversionFromBaseType, - ERRID.ERR_ConversionToDerivedType)), method.Locations(0)) + ERRID.ERR_ConversionToDerivedType)), method.GetFirstLocation()) result = False Else Return False @@ -450,7 +450,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If diagnosticsOpt IsNot Nothing Then diagnosticsOpt.Add(ErrorFactory.ErrorInfo(If(targetType Is method.ContainingSymbol, ERRID.ERR_ConversionFromDerivedType, - ERRID.ERR_ConversionToBaseType)), method.Locations(0)) + ERRID.ERR_ConversionToBaseType)), method.GetFirstLocation()) result = False Else Return False @@ -460,7 +460,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End If If result AndAlso diagnosticsOpt IsNot Nothing Then - diagnosticsOpt.Add(method.Locations(0), useSiteInfo) + diagnosticsOpt.Add(method.GetFirstLocation(), useSiteInfo) End If Return result diff --git a/src/Compilers/VisualBasic/Portable/Symbols/AliasSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/AliasSymbol.vb index f1d8efd4b929b..567c049fc21a2 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/AliasSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/AliasSymbol.vb @@ -250,7 +250,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' Returns a hash code for the current object. ''' Public Overrides Function GetHashCode() As Integer - Return If(Me.Locations.Length > 0, Me.Locations(0).GetHashCode(), Me.Name.GetHashCode()) + Return If(Me.Locations.Length > 0, Me.GetFirstLocation().GetHashCode(), Me.Name.GetHashCode()) End Function Friend Overrides Function Accept(Of TArg, TResult)(visitor As VisualBasicSymbolVisitor(Of TArg, TResult), a As TArg) As TResult diff --git a/src/Compilers/VisualBasic/Portable/Symbols/AnonymousTypes/AnonymousTypeManager_Templates.vb b/src/Compilers/VisualBasic/Portable/Symbols/AnonymousTypes/AnonymousTypeManager_Templates.vb index 615ced1480977..3d8db2a7edfa7 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/AnonymousTypes/AnonymousTypeManager_Templates.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/AnonymousTypes/AnonymousTypeManager_Templates.vb @@ -30,7 +30,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Private Sub CheckSourceLocationSeen(anonymous As AnonymousTypeOrDelegatePublicSymbol) #If DEBUG Then - Dim location As Location = anonymous.Locations(0) + Dim location As Location = anonymous.GetFirstLocation() If location.IsInSource Then If Me.AreTemplatesSealed Then Debug.Assert(Me._sourceLocationsSeen.ContainsKey(location)) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplicitNamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplicitNamedTypeSymbol.vb index 2000f2a6febbb..797014959f8af 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplicitNamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/ImplicitNamedTypeSymbol.vb @@ -54,7 +54,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' check that System.Object is available. ' Although submission semantically doesn't have a base class we need to emit one. Dim info = baseType.GetUseSiteInfo() - diagnostics.Add(info, Locations(0)) + diagnostics.Add(info, GetFirstLocation()) Return If(Me.TypeKind = TypeKind.Submission, Nothing, baseType) End Function diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverloadingHelper.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverloadingHelper.vb index 662d9cd187665..e41b2733a4f5a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverloadingHelper.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverloadingHelper.vb @@ -113,9 +113,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols member.SetMetadataName(metadataName) ' Remember the metadata name of the lexically first override - If firstOverrideName Is Nothing OrElse compilation.CompareSourceLocations(member.Locations(0), locationOfFirstOverride) < 0 Then + If firstOverrideName Is Nothing OrElse compilation.CompareSourceLocations(member.GetFirstLocation(), locationOfFirstOverride) < 0 Then firstOverrideName = metadataName - locationOfFirstOverride = member.Locations(0) + locationOfFirstOverride = member.GetFirstLocation() End If End If End If @@ -131,7 +131,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim firstName As String = Nothing Dim locationOfFirstName As Location = Nothing For Each member In overloadedMembers - Dim memberLocation = member.Locations(0) + Dim memberLocation = member.GetFirstLocation() If firstName Is Nothing OrElse compilation.CompareSourceLocations(memberLocation, locationOfFirstName) < 0 Then firstName = member.Name locationOfFirstName = memberLocation @@ -153,7 +153,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' members. For the lookup we are doing, it doesn't matter which partial we use because Imports and Options can't ' affect a lookup that ignores extension methods. Dim binder = BinderBuilder.CreateBinderForType(DirectCast(container.ContainingModule, SourceModuleSymbol), - container.Locations(0).PossiblyEmbeddedOrMySourceTree(), + container.GetFirstLocation().PossiblyEmbeddedOrMySourceTree(), container) Dim result = LookupResult.GetInstance() diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb index 65b5d02fe85e3..37854e7a5cbbe 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/OverrideHidingHelper.vb @@ -153,7 +153,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols OverrideHidingHelper(Of MethodSymbol).CheckOverrideMember(methodMember, methodMember.OverriddenMembers, diagnostics) ElseIf methodMember.IsNotOverridable Then 'Method is not marked as Overrides but is marked as Not Overridable - diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_NotOverridableRequiresOverrides), methodMember.Locations(0))) + diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_NotOverridableRequiresOverrides), methodMember.GetFirstLocation())) End If End If Case SymbolKind.Property @@ -161,7 +161,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If propMember.IsOverrides Then OverrideHidingHelper(Of PropertySymbol).CheckOverrideMember(propMember, propMember.OverriddenMembers, diagnostics) ElseIf propMember.IsNotOverridable Then - diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_NotOverridableRequiresOverrides), propMember.Locations(0))) + diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_NotOverridableRequiresOverrides), propMember.GetFirstLocation())) End If End Select @@ -184,7 +184,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If Not (container.IsMustInherit OrElse container.IsNotInheritable) Then For Each member In container.GetMembers() If member.IsMustOverride Then - diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_MustOverridesInClass1, container.Name), container.Locations(0))) + diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_MustOverridesInClass1, container.Name), container.GetFirstLocation())) Exit For End If Next @@ -250,7 +250,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols member, CustomSymbolDisplayFormatter.QualifiedName(member.ContainingType), CustomSymbolDisplayFormatter.ShortErrorName(container)), - container.Locations(0))) + container.GetFirstLocation())) Else diagnosticInfos.Add(ErrorFactory.ErrorInfo(ERRID.ERR_UnimplementedMustOverride, member.ContainingType, member)) End If @@ -264,7 +264,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_BaseOnlyClassesMustBeExplicit2, CustomSymbolDisplayFormatter.ShortErrorName(container), New CompoundDiagnosticInfo(diagnosticInfos.ToArrayAndFree())), - container.Locations(0))) + container.GetFirstLocation())) Else diagnosticInfos.Free() End If @@ -411,7 +411,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols AssociatedSymbolName(associatedhiddenSymbol), hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) End If Return @@ -421,14 +421,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols hidingMember.GetKindText(), hidingMember.Name, associatedhiddenSymbol.GetKindText(), AssociatedSymbolName(associatedhiddenSymbol), hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) ElseIf associatedhidingSymbol IsNot Nothing Then ' implicitly defined member hiding explicitly defined member diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.WRN_SynthMemberShadowsMember5, associatedhidingSymbol.GetKindText(), AssociatedSymbolName(associatedhidingSymbol), hidingMember.Name, hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - associatedhidingSymbol.Locations(0))) + associatedhidingSymbol.GetFirstLocation())) ElseIf hidingMember.Kind = hiddenMember.Kind AndAlso (hidingMember.Kind = SymbolKind.Property OrElse hidingMember.Kind = SymbolKind.Method) AndAlso Not (hiddenMember.IsWithEventsProperty OrElse hidingMember.IsWithEventsProperty) Then @@ -444,14 +444,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(id, hidingMember.GetKindText(), hidingMember.Name, hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) Else ' all other hiding scenarios. - Debug.Assert(hidingMember.Locations(0).IsInSource) + Debug.Assert(hidingMember.GetFirstLocation().IsInSource) diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.WRN_OverrideType5, hidingMember.GetKindText(), hidingMember.Name, hiddenMember.GetKindText(), hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) End If End Sub @@ -466,7 +466,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Private Shared Sub ReportShadowingMustOverrideError(hidingMember As Symbol, hiddenMember As Symbol, diagnostics As BindingDiagnosticBag) - Debug.Assert(hidingMember.Locations(0).IsInSource) + Debug.Assert(hidingMember.GetFirstLocation().IsInSource) If hidingMember.IsAccessor() Then ' accessor hiding non-accessorTODO @@ -476,11 +476,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols associatedHidingSymbol.GetKindText(), associatedHidingSymbol.Name, hiddenMember.ContainingType.GetKindText(), CustomSymbolDisplayFormatter.ShortErrorName(hiddenMember.ContainingType)), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) Else ' Basic hiding case diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_CantShadowAMustOverride1, hidingMember), - hidingMember.Locations(0))) + hidingMember.GetFirstLocation())) End If End Sub @@ -850,7 +850,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ReportBadOverriding(ERRID.ERR_CannotOverrideInAccessibleMember, member, overriddenMembersResult.InaccessibleMembers(0), diagnostics) Else diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_OverrideNotNeeded3, member.GetKindText(), member.Name), - member.Locations(0))) + member.GetFirstLocation())) End If ElseIf overriddenMembers.Length > 1 Then ' Multiple members we could be overriding. Create a single error message that lists them all. @@ -864,7 +864,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols overriddenMembers(0), CustomSymbolDisplayFormatter.ShortErrorName(overriddenMembers(0).ContainingType), New CompoundDiagnosticInfo(diagnosticInfos.ToArrayAndFree())), - member.Locations(0))) + member.GetFirstLocation())) Else ' overriding exactly one member. Dim overriddenMember As TSymbol = overriddenMembers(0) @@ -906,14 +906,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' We can't do that, so issue an error. diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_InAccessibleOverridingMethod5, member, member.ContainingType, overriddenMember, overriddenMember.ContainingType, inaccessibleMember.ContainingType), - member.Locations(0))) + member.GetFirstLocation())) End If Next Dim useSiteInfo = overriddenMember.GetUseSiteInfo() - If Not diagnostics.Add(useSiteInfo, member.Locations(0)) AndAlso + If Not diagnostics.Add(useSiteInfo, member.GetFirstLocation()) AndAlso member.Kind = SymbolKind.Property Then ' No overriding errors found in member. If its a property, its accessors might have issues. @@ -991,7 +991,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End If End If - diagnostics.Add(overriddenAccessor.GetUseSiteInfo(), overridingAccessor.Locations(0)) + diagnostics.Add(overriddenAccessor.GetUseSiteInfo(), overridingAccessor.GetFirstLocation()) End If End Sub @@ -1001,7 +1001,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols overriddenMember As Symbol, diagnostics As BindingDiagnosticBag) diagnostics.Add(New VBDiagnostic(New BadSymbolDiagnostic(overriddenMember, id, overridingMember, overriddenMember), - overridingMember.Locations(0))) + overridingMember.GetFirstLocation())) End Sub ' Are the declared accessibility of the two symbols consistent? If not, return the error code to use. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb index 3f5fc06b97f53..8d67017c6e00a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceComplexParameterSymbol.vb @@ -317,7 +317,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Asking for the default value earlier than that can lead to infinite recursion. Instead, pass in the m_lazyDefaultValue. If the value hasn't ' been computed yet, the new symbol will compute it. - Return New SourceComplexParameterSymbol(newContainingSymbol, Me.Name, Me.Ordinal, Me.Type, Me.Locations(0), _syntaxRef, _flags, _lazyDefaultValue) + Return New SourceComplexParameterSymbol(newContainingSymbol, Me.Name, Me.Ordinal, Me.Type, Me.GetFirstLocation(), _syntaxRef, _flags, _lazyDefaultValue) End Function ' Create a parameter from syntax. diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEnumConstantSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEnumConstantSymbol.vb index 861bbf1d4cd27..5d9eb0593bcfc 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEnumConstantSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEnumConstantSymbol.vb @@ -145,7 +145,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If Not otherValue.IsBad Then Dim overflowKind = EnumConstantHelper.OffsetValue(otherValue, _otherConstantOffset, value) If overflowKind = EnumOverflowKind.OverflowReport Then - diagnostics.Add(ERRID.ERR_ExpressionOverflow1, Locations(0), Me) + diagnostics.Add(ERRID.ERR_ExpressionOverflow1, GetFirstLocation(), Me) End If End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb index 3ac3dd0f2e21a..1a485172357dc 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceEventSymbol.vb @@ -106,21 +106,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If _addMethod Is Nothing Then _addMethod = accessor Else - diagnostics.Add(ERRID.ERR_DuplicateAddHandlerDef, accessor.Locations(0)) + diagnostics.Add(ERRID.ERR_DuplicateAddHandlerDef, accessor.GetFirstLocation()) End If Case MethodKind.EventRemove If _removeMethod Is Nothing Then _removeMethod = accessor Else - diagnostics.Add(ERRID.ERR_DuplicateRemoveHandlerDef, accessor.Locations(0)) + diagnostics.Add(ERRID.ERR_DuplicateRemoveHandlerDef, accessor.GetFirstLocation()) End If Case MethodKind.EventRaise If _raiseMethod Is Nothing Then _raiseMethod = accessor Else - diagnostics.Add(ERRID.ERR_DuplicateRaiseEventDef, accessor.Locations(0)) + diagnostics.Add(ERRID.ERR_DuplicateRaiseEventDef, accessor.GetFirstLocation()) End If Case Else @@ -755,7 +755,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim sourceModule = DirectCast(Me.ContainingModule, SourceModuleSymbol) Dim diagnostics = BindingDiagnosticBag.GetInstance() type.CheckAllConstraints(DeclaringCompilation.LanguageVersion, - Locations(0), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) + GetFirstLocation(), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) sourceModule.AtomicSetFlagAndStoreDiagnostics(_lazyState, StateFlags.TypeConstraintsChecked, 0, diagnostics) diagnostics.Free() End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb index 32d6fcf60ca26..3599b8e175d10 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFieldSymbol.vb @@ -244,7 +244,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If startsCycle Then diagnostics.Clear() - diagnostics.Add(ERRID.ERR_CircularEvaluation1, Locations(0), CustomSymbolDisplayFormatter.ShortErrorName(Me)) + diagnostics.Add(ERRID.ERR_CircularEvaluation1, GetFirstLocation(), CustomSymbolDisplayFormatter.ShortErrorName(Me)) End If SetLazyConstantTuple(constantTuple, diagnostics) @@ -531,7 +531,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' We sort fields that belong to the same compilation by location to process cycles in deterministic order. ' Relative order between compilations is not important, cycles do not cross compilation boundaries. fieldsInvolvedInCycles.AddRange(graph.Keys.GroupBy(Function(f) f.DeclaringCompilation). - SelectMany(Function(g) g.OrderByDescending(Function(f1, f2) g.Key.CompareSourceLocations(f1.Locations(0), f2.Locations(0))))) + SelectMany(Function(g) g.OrderByDescending(Function(f1, f2) g.Key.CompareSourceLocations(f1.GetFirstLocation(), f2.GetFirstLocation())))) End If Do diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFile.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFile.vb index d811f22c45274..f4ecda7998c79 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFile.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceFile.vb @@ -340,7 +340,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If aliasImportsOpt IsNot Nothing Then For Each aliasImport In aliasImportsOpt.Values ValidateImportsClause(compilation, clauseDiagnostics, aliasImport.Alias.Target, - aliasImport.Dependencies, aliasImport.Alias.Locations(0), + aliasImport.Dependencies, aliasImport.Alias.GetFirstLocation(), aliasImport.ImportsClausePosition, diagnostics) Next End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb index 5f636c7163de5..039cc9ed494f3 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb @@ -392,7 +392,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If container IsNot Nothing Then Debug.Assert(container.IsInterfaceType() AndAlso container.HasVariance()) - diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_VarianceInterfaceNesting), Locations(0))) + diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_VarianceInterfaceNesting), GetFirstLocation())) End If End Sub @@ -981,7 +981,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If asClause IsNot Nothing Then location = asClause.Type.GetLocation() Else - location = method.Locations(0) + location = method.GetFirstLocation() End If ReportDiagnostics(diagnostics, location, infosBuffer) @@ -1018,7 +1018,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If syntax IsNot Nothing AndAlso syntax.AsClause IsNot Nothing Then location = syntax.AsClause.Type.GetLocation() Else - location = param.Locations(0) + location = param.GetFirstLocation() End If ReportDiagnostics(diagnostics, location, infosBuffer) @@ -1043,7 +1043,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols For Each constraint As TypeSymbol In param.ConstraintTypesNoUseSiteDiagnostics GenerateVarianceDiagnosticsForType(constraint, VarianceKind.In, VarianceContext.Constraint, infosBuffer) If HaveDiagnostics(infosBuffer) Then - Dim location As Location = param.Locations(0) + Dim location As Location = param.GetFirstLocation() For Each constraintInfo As TypeParameterConstraint In param.GetConstraints() If constraintInfo.TypeConstraint IsNot Nothing AndAlso @@ -1089,7 +1089,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If syntax IsNot Nothing AndAlso syntax.AsClause IsNot Nothing Then location = syntax.AsClause.Type.GetLocation() Else - location = [property].Locations(0) + location = [property].GetFirstLocation() End If ReportDiagnostics(diagnostics, location, infosBuffer) @@ -1125,7 +1125,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If syntax IsNot Nothing AndAlso syntax.AsClause IsNot Nothing Then location = syntax.AsClause.Type.GetLocation() Else - location = [event].Locations(0) + location = [event].GetFirstLocation() End If ReportDiagnostics(diagnostics, location, infosBuffer) @@ -1920,7 +1920,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Debug.Assert(implParameter.Locations.Length = 1) diagnostics.Add(ERRID.ERR_PartialMethodParamNamesMustMatch3, - implParameter.Locations(0), + implParameter.GetFirstLocation(), implParameter.Name, declParameter.Name, implMethod.Name) End If Next @@ -1941,7 +1941,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Debug.Assert(implParameter.Locations.Length = 1) diagnostics.Add(ERRID.ERR_PartialMethodTypeParamNameMismatch3, - implParameter.Locations(0), + implParameter.GetFirstLocation(), implParameter.Name, declParameter.Name, implMethod.Name) End If @@ -2165,7 +2165,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim symbolToReportErrorOn As Symbol = If(firstField.AssociatedSymbol, DirectCast(firstField, Symbol)) Debug.Assert(symbolToReportErrorOn.Locations.Length > 0) diagnostics.Add(ERRID.ERR_RecordCycle2, - symbolToReportErrorOn.Locations(0), + symbolToReportErrorOn.GetFirstLocation(), firstField.ContainingType.Name, New CompoundDiagnosticInfo(diagnosticInfos.ToArrayAndFree())) @@ -2250,10 +2250,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End If ' We use simple comparison based on source location - Dim typeToTestLocation = typeToTest.Locations(0) + Dim typeToTestLocation = typeToTest.GetFirstLocation() Debug.Assert(Me.Locations.Length > 0) - Dim structBeingAnalyzedLocation = Me.Locations(0) + Dim structBeingAnalyzedLocation = Me.GetFirstLocation() Dim compilation = Me.DeclaringCompilation Dim fileCompResult = compilation.CompareSourceLocations(typeToTestLocation, structBeingAnalyzedLocation) @@ -2285,11 +2285,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols defaultPropertyName = name If Not defaultProperty.ShadowsExplicitly Then - CheckDefaultPropertyAgainstAllBases(Me, defaultPropertyName, propertySymbol.Locations(0), diagBag) + CheckDefaultPropertyAgainstAllBases(Me, defaultPropertyName, propertySymbol.GetFirstLocation(), diagBag) End If Else ' "'Default' can be applied to only one property name in a {0}." - diagBag.Add(ERRID.ERR_DuplicateDefaultProps1, propertySymbol.Locations(0), GetKindText()) + diagBag.Add(ERRID.ERR_DuplicateDefaultProps1, propertySymbol.GetFirstLocation(), GetKindText()) End If Exit For End If @@ -2306,7 +2306,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If Not propertySymbol.IsDefault Then ' "'{0}' and '{1}' cannot overload each other because only one is declared 'Default'." - diagBag.Add(ERRID.ERR_DefaultMissingFromProperty2, propertySymbol.Locations(0), defaultProperty, propertySymbol) + diagBag.Add(ERRID.ERR_DefaultMissingFromProperty2, propertySymbol.GetFirstLocation(), defaultProperty, propertySymbol) End If End If Next @@ -2446,12 +2446,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If explicitlyShadows Then If Not shadowsExplicitly Then Debug.Assert(symbol.Locations.Length > 0) - diagBag.Add(ERRID.ERR_MustShadow2, symbol.Locations(0), symbol.GetKindText(), symbol.Name) + diagBag.Add(ERRID.ERR_MustShadow2, symbol.GetFirstLocation(), symbol.GetKindText(), symbol.Name) End If ElseIf explicitlyOverloads Then If Not overridesExplicitly AndAlso Not overloadsExplicitly Then Debug.Assert(symbol.Locations.Length > 0) - diagBag.Add(ERRID.ERR_MustBeOverloads2, symbol.Locations(0), symbol.GetKindText(), symbol.Name) + diagBag.Add(ERRID.ERR_MustBeOverloads2, symbol.GetFirstLocation(), symbol.GetKindText(), symbol.Name) End If End If End If @@ -2950,14 +2950,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' "{0} '{1}' implicitly defines a member '{2}' which has the same name as a type parameter." Binder.ReportDiagnostic(diagBag, - symImplicitlyDefinedBy.Locations(0), + symImplicitlyDefinedBy.GetFirstLocation(), ERRID.ERR_SyntMemberShadowsGenericParam3, symImplicitlyDefinedBy.GetKindText(), symImplicitlyDefinedBy.Name, sym.Name) Else ' "'{0}' has the same name as a type parameter." - Binder.ReportDiagnostic(diagBag, sym.Locations(0), ERRID.ERR_ShadowingGenericParamWithMember1, sym.Name) + Binder.ReportDiagnostic(diagBag, sym.GetFirstLocation(), ERRID.ERR_ShadowingGenericParamWithMember1, sym.Name) End If End If Next @@ -3051,7 +3051,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' "{0} '{1}' implicitly defines '{2}', which conflicts with a member of the same name in {3} '{4}'." Binder.ReportDiagnostic( diagBag, - firstAssociatedSymbol.Locations(0), + firstAssociatedSymbol.GetFirstLocation(), ERRID.ERR_SynthMemberClashesWithMember5, firstAssociatedSymbol.GetKindText(), OverrideHidingHelper.AssociatedSymbolName(firstAssociatedSymbol), @@ -3071,7 +3071,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols '{0} '{1}' implicitly defines '{2}', which conflicts with a member implicitly declared for {3} '{4}' in {5} '{6}'. Binder.ReportDiagnostic( diagBag, - firstAssociatedSymbol.Locations(0), + firstAssociatedSymbol.GetFirstLocation(), ERRID.ERR_SynthMemberClashesWithSynth7, firstAssociatedSymbol.GetKindText(), OverrideHidingHelper.AssociatedSymbolName(firstAssociatedSymbol), @@ -3087,7 +3087,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' "{0} '{1}' conflicts with a member implicitly declared for {2} '{3}' in {4} '{5}'." Binder.ReportDiagnostic( diagBag, - secondSymbol.Locations(0), + secondSymbol.GetFirstLocation(), ERRID.ERR_MemberClashesWithSynth6, secondSymbol.GetKindText(), secondSymbol.Name, @@ -3107,7 +3107,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' "'{0}' is already declared in this {1}." Binder.ReportDiagnostic( diagBag, - firstSymbol.Locations(0), + firstSymbol.GetFirstLocation(), ERRID.ERR_MultiplyDefinedEnumMember2, firstSymbol.Name, Me.GetKindText()) @@ -3119,7 +3119,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' "'{0}' is already declared as '{1}' in this {2}." Binder.ReportDiagnostic( diagBag, - firstSymbol.Locations(0), + firstSymbol.GetFirstLocation(), ERRID.ERR_MultiplyDefinedType3, firstSymbol.Name, If(includeKind, @@ -3422,11 +3422,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(New VBDiagnostic(diag, GetImplementsLocation(iface))) ElseIf implementingSet.Count = 1 Then ' Otherwise, a duplicate implementation error is reported above - diagnostics.Add(useSiteInfo, implementingSet.Single.Locations(0)) + diagnostics.Add(useSiteInfo, implementingSet.Single.GetFirstLocation()) End If ElseIf implementingSet.Count = 1 Then - diagnostics.Add(useSiteInfo, implementingSet.Single.Locations(0)) + diagnostics.Add(useSiteInfo, implementingSet.Single.GetFirstLocation()) End If End If Next @@ -3578,7 +3578,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' only report diagnostics if the signature is considered equal following VB rules. If (comparisonResults And Not SymbolComparisonResults.MismatchesForConflictingMethods) = 0 Then - ReportOverloadsErrors(comparisonResults, member, nextMember, member.Locations(0), diagnostics) + ReportOverloadsErrors(comparisonResults, member, nextMember, member.GetFirstLocation(), diagnostics) Exit For End If End If @@ -3717,7 +3717,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_MatchingOperatorExpected2, SyntaxFacts.GetText(OverloadResolution.GetOperatorTokenKind(nameOfThePair)), - method), method.Locations(0)) + method), method.GetFirstLocation()) End If Return True @@ -3759,7 +3759,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' only report diagnostics if the signature is considered equal following VB rules. If (comparisonResults And significantDiff) = 0 Then - ReportOverloadsErrors(comparisonResults, method, nextMethod, method.Locations(0), diagnostics) + ReportOverloadsErrors(comparisonResults, method, nextMethod, method.GetFirstLocation(), diagnostics) Return True End If Next diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberFieldSymbol.vb index 8b9df817adda8..59e19a98b7865 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberFieldSymbol.vb @@ -37,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim sourceModule = DirectCast(Me.ContainingModule, SourceModuleSymbol) Dim diagnostics = BindingDiagnosticBag.GetInstance() Type.CheckAllConstraints(DeclaringCompilation.LanguageVersion, - Locations(0), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) + GetFirstLocation(), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) sourceModule.AtomicSetFlagAndStoreDiagnostics(_lazyState, StateFlags.TypeConstraintsChecked, 0, diagnostics) diagnostics.Free() End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb index 7e379aeeae786..2919fdf069a64 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb @@ -1628,7 +1628,7 @@ lReportErrorOnTwoTokens: diagnostics.Add(ERRID.ERR_ExtensionMethodNotInModule, arguments.AttributeSyntaxOpt.GetLocation()) ElseIf Me.ParameterCount = 0 Then - diagnostics.Add(ERRID.ERR_ExtensionMethodNoParams, Me.Locations(0)) + diagnostics.Add(ERRID.ERR_ExtensionMethodNoParams, Me.GetFirstLocation()) Else Debug.Assert(Me.IsShared) @@ -1636,13 +1636,13 @@ lReportErrorOnTwoTokens: Dim firstParam As ParameterSymbol = Me.Parameters(0) If firstParam.IsOptional Then - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodOptionalFirstArg), firstParam.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodOptionalFirstArg), firstParam.GetFirstLocation()) ElseIf firstParam.IsParamArray Then - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodParamArrayFirstArg), firstParam.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodParamArrayFirstArg), firstParam.GetFirstLocation()) ElseIf Not Me.ValidateGenericConstraintsOnExtensionMethodDefinition() Then - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodUncallable1, Me.Name), Me.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionMethodUncallable1, Me.Name), Me.GetFirstLocation()) End If End If @@ -1652,7 +1652,7 @@ lReportErrorOnTwoTokens: ' Check for optional parameters For Each parameter In Me.Parameters If parameter.IsOptional Then - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_InvalidOptionalParameterUsage1, "WebMethod"), Me.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_InvalidOptionalParameterUsage1, "WebMethod"), Me.GetFirstLocation()) End If Next @@ -1744,7 +1744,7 @@ lReportErrorOnTwoTokens: ElseIf attrData.IsTargetAttribute(AttributeDescription.ConditionalAttribute) Then If Not Me.IsSub Then ' BC41007: Attribute 'Conditional' is only valid on 'Sub' declarations. - diagnostics.Add(ERRID.WRN_ConditionalNotValidOnFunction, Me.Locations(0)) + diagnostics.Add(ERRID.WRN_ConditionalNotValidOnFunction, Me.GetFirstLocation()) End If ElseIf VerifyObsoleteAttributeAppliedToMethod(arguments, AttributeDescription.ObsoleteAttribute) Then ElseIf VerifyObsoleteAttributeAppliedToMethod(arguments, AttributeDescription.DeprecatedAttribute) Then @@ -1785,7 +1785,7 @@ lReportErrorOnTwoTokens: If arguments.Attribute.IsTargetAttribute(description) Then ' Obsolete Attribute is not allowed on event accessors. If Me.IsAccessor() AndAlso Me.AssociatedSymbol.Kind = SymbolKind.Event Then - DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.ERR_ObsoleteInvalidOnEventMember, Me.Locations(0), description.FullName) + DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.ERR_ObsoleteInvalidOnEventMember, Me.GetFirstLocation(), description.FullName) End If Return True @@ -2192,7 +2192,7 @@ lReportErrorOnTwoTokens: ' match Dev10 and report errors on the parameter type syntax instead. param.Type.CheckAllConstraints( DeclaringCompilation.LanguageVersion, - param.Locations(0), diagBag, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagBag, sourceModule.ContainingAssembly)) + param.GetFirstLocation(), diagBag, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagBag, sourceModule.ContainingAssembly)) End If Next diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb index 44be9f063a22b..179053a9e51e8 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb @@ -963,10 +963,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols typeParameterSet.Add(s.Name) If ShadowsTypeParameter(s) Then - Binder.ReportDiagnostic(diagBag, s.Locations(0), ERRID.WRN_ShadowingGenericParamWithParam1, s.Name) + Binder.ReportDiagnostic(diagBag, s.GetFirstLocation(), ERRID.WRN_ShadowingGenericParamWithParam1, s.Name) End If Else - Binder.ReportDiagnostic(diagBag, s.Locations(0), ERRID.ERR_DuplicateTypeParamName1, s.Name) + Binder.ReportDiagnostic(diagBag, s.GetFirstLocation(), ERRID.ERR_DuplicateTypeParamName1, s.Name) End If Next End If @@ -1447,7 +1447,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' script, submission and implicit classes have no identifier location: location = If(syntax.Kind = SyntaxKind.CompilationUnit OrElse syntax.Kind = SyntaxKind.NamespaceBlock, - Locations(0), + GetFirstLocation(), GetTypeIdentifierToken(syntax).GetLocation()) End If @@ -2236,12 +2236,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Select Case Me.TypeKind Case TypeKind.Class If attrData.IsTargetAttribute(AttributeDescription.CaseInsensitiveExtensionAttribute) Then - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionOnlyAllowedOnModuleSubOrFunction), Me.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_ExtensionOnlyAllowedOnModuleSubOrFunction), Me.GetFirstLocation()) decoded = True ElseIf attrData.IsTargetAttribute(AttributeDescription.VisualBasicComClassAttribute) Then If Me.IsGenericType Then - diagnostics.Add(ERRID.ERR_ComClassOnGeneric, Me.Locations(0)) + diagnostics.Add(ERRID.ERR_ComClassOnGeneric, Me.GetFirstLocation()) Else Interlocked.CompareExchange(_comClassData, New ComClassData(attrData), Nothing) End If @@ -2289,7 +2289,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ElseIf attrData.IsTargetAttribute(AttributeDescription.VisualBasicComClassAttribute) Then ' Can't apply ComClassAttribute to a Module - diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_InvalidAttributeUsage2, AttributeDescription.VisualBasicComClassAttribute.Name, Me.Name), Me.Locations(0)) + diagnostics.Add(ErrorFactory.ErrorInfo(ERRID.ERR_InvalidAttributeUsage2, AttributeDescription.VisualBasicComClassAttribute.Name, Me.Name), Me.GetFirstLocation()) decoded = True End If End Select @@ -2303,7 +2303,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim defaultProperty = DefaultPropertyName If Not String.IsNullOrEmpty(defaultProperty) AndAlso Not IdentifierComparison.Equals(defaultProperty, attributeValue) Then - diagnostics.Add(ERRID.ERR_ConflictDefaultPropertyAttribute, Locations(0), Me) + diagnostics.Add(ERRID.ERR_ConflictDefaultPropertyAttribute, GetFirstLocation(), Me) End If ElseIf attrData.IsTargetAttribute(AttributeDescription.SerializableAttribute) Then @@ -2454,7 +2454,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.Microsoft_VisualBasic_CompilerServices_StandardModuleAttribute__ctor, Me.DeclaringCompilation, - Locations(0), + GetFirstLocation(), diagnostics) End If End Sub diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb index c3343d68e89e9..61664aa6d4007 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol_ComClass.vb @@ -138,39 +138,39 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Can't specify the same value for iid and eventsid ' It is not an error to reuse the classid guid though. If InterfaceId IsNot Nothing AndAlso EventId IsNot Nothing AndAlso interfaceGuid = eventGuid Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassDuplicateGuids1, comClass.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassDuplicateGuids1, comClass.Name) End If End If ' Can't specify ComClass and Guid If comClass.HasGuidAttribute() Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.GuidAttribute.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.GuidAttribute.Name) End If ' Can't specify ComClass and ClassInterface If comClass.HasClassInterfaceAttribute() Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ClassInterfaceAttribute.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ClassInterfaceAttribute.Name) End If ' Can't specify ComClass and ComSourceInterfaces If comClass.HasComSourceInterfacesAttribute() Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ComSourceInterfacesAttribute.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ComSourceInterfacesAttribute.Name) End If ' Can't specify ComClass and ComVisible(False) If Not GetComVisibleState(comClass) Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ComVisibleAttribute.Name & "(False)") + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassAndReservedAttribute1, AttributeDescription.ComVisibleAttribute.Name & "(False)") End If 'Class must be Public If comClass.DeclaredAccessibility <> Accessibility.Public Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassRequiresPublicClass1, comClass.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassRequiresPublicClass1, comClass.Name) Else Dim container As NamedTypeSymbol = comClass.ContainingType While container IsNot Nothing If container.DeclaredAccessibility <> Accessibility.Public Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassRequiresPublicClass2, + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassRequiresPublicClass2, comClass.Name, container.Name) Exit While End If @@ -181,7 +181,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Class cannot be Abstract If comClass.IsMustInherit Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_ComClassCantBeAbstract0) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_ComClassCantBeAbstract0) End If ' Check for nest type name collisions on this class and @@ -192,7 +192,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols GetComClassMembers(comClass, interfaceMembers, eventMembers, haveDefaultProperty, diagnostics) If interfaceMembers.Count = 0 AndAlso eventMembers.Count = 0 Then - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.WRN_ComClassNoMembers1, comClass.Name) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.WRN_ComClassNoMembers1, comClass.Name) ElseIf Not diagnostics.HasAnyErrors() Then Dim comClassInterface As NamedTypeSymbol = New SynthesizedComInterface(comClass, interfaceMembers) @@ -211,26 +211,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols (EventId IsNot Nothing AndAlso interfaces.Length > 1) Then Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_GuidAttribute__ctor, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) End If ' Should be able to emit ClassInterfaceAttribute. Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_ClassInterfaceAttribute__ctorClassInterfaceType, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) ' Should be able to emit ComSourceInterfacesAttribute and InterfaceTypeAttribute if there is an event interface. If interfaces.Length > 1 Then Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_ComSourceInterfacesAttribute__ctorString, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_InterfaceTypeAttribute__ctorInt16, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) End If @@ -238,7 +238,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If interfaces.Length > 0 Then Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_ComVisibleAttribute__ctor, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) End If @@ -265,7 +265,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Should be able to emit DispIdAttribute on members. Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Runtime_InteropServices_DispIdAttribute__ctor, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) End If @@ -273,7 +273,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Should be able to emit DefaultMemberAttribute. Binder.ReportUseSiteInfoForSynthesizedAttribute(WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor, comClass.DeclaringCompilation, - comClass.Locations(0), + comClass.GetFirstLocation(), diagnostics) End If @@ -287,7 +287,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Private Shared Function ValidateComClassGuid(comClass As SourceNamedTypeSymbol, id As String, diagnostics As BindingDiagnosticBag, Optional ByRef guidVal As Guid = Nothing) As Boolean If id IsNot Nothing Then If Not Guid.TryParseExact(id, "D", guidVal) Then '32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000 - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.ERR_BadAttributeUuid2, AttributeDescription.VisualBasicComClassAttribute.Name, id) + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.ERR_BadAttributeUuid2, AttributeDescription.VisualBasicComClassAttribute.Name, id) Return False End If Else @@ -329,7 +329,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols For Each member As Symbol In comClass.GetMembers(interfaceName) ' Error--name collision on this class - Binder.ReportDiagnostic(diagnostics, member.Locations(0), ERRID.ERR_MemberConflictWithSynth4, + Binder.ReportDiagnostic(diagnostics, member.GetFirstLocation(), ERRID.ERR_MemberConflictWithSynth4, SyntaxFacts.GetText(SyntaxKind.InterfaceKeyword) & " " & interfaceName, AttributeDescription.VisualBasicComClassAttribute.Name, SyntaxFacts.GetText(SyntaxKind.ClassKeyword), @@ -343,7 +343,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If member.DeclaredAccessibility <> Accessibility.Private Then ' Warning--name shadows a base class member - Binder.ReportDiagnostic(diagnostics, comClass.Locations(0), ERRID.WRN_ComClassInterfaceShadows5, + Binder.ReportDiagnostic(diagnostics, comClass.GetFirstLocation(), ERRID.WRN_ComClassInterfaceShadows5, comClass.Name, SyntaxFacts.GetText(SyntaxKind.InterfaceKeyword), interfaceName, @@ -426,7 +426,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Warn for Property X As Object : Set(ByVal o As Object) If prop.Type.IsObjectType() AndAlso prop.SetMethod IsNot Nothing Then - Binder.ReportDiagnostic(diagnostics, prop.Locations(0), ERRID.WRN_ComClassPropertySetObject1, prop) + Binder.ReportDiagnostic(diagnostics, prop.GetFirstLocation(), ERRID.WRN_ComClassPropertySetObject1, prop) End If interfaceMembers.Add(New KeyValuePair(Of Symbol, Integer)(prop, GetUserSpecifiedDispId(prop, diagnostics))) @@ -452,7 +452,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Case SymbolKind.Method If DirectCast(member, MethodSymbol).IsGenericMethod Then ' Generic methods cannot be exposed to COM - Binder.ReportDiagnostic(diagnostics, member.Locations(0), ERRID.ERR_ComClassGenericMethod) + Binder.ReportDiagnostic(diagnostics, member.GetFirstLocation(), ERRID.ERR_ComClassGenericMethod) End If interfaceMembers.Add(New KeyValuePair(Of Symbol, Integer)(member, GetUserSpecifiedDispId(member, diagnostics))) @@ -493,13 +493,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' for the Default property. If dispId = 0 Then If target.Kind <> SymbolKind.Property OrElse Not DirectCast(target, PropertySymbol).IsDefault Then - Binder.ReportDiagnostic(diagnostics, target.Locations(0), ERRID.ERR_ComClassReservedDispIdZero1, target.Name) + Binder.ReportDiagnostic(diagnostics, target.GetFirstLocation(), ERRID.ERR_ComClassReservedDispIdZero1, target.Name) End If ' Validate that the user has not used negative DispId's which ' are reserved by COM and the runtime. ElseIf dispId < 0 Then - Binder.ReportDiagnostic(diagnostics, target.Locations(0), ERRID.ERR_ComClassReservedDispId1, target.Name) + Binder.ReportDiagnostic(diagnostics, target.GetFirstLocation(), ERRID.ERR_ComClassReservedDispId1, target.Name) End If Return dispId diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb index 411a8df8d7eed..83b5833d70f15 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertyAccessorSymbol.vb @@ -265,7 +265,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' match Dev10 and report errors on the parameter type syntax instead. param.Type.CheckAllConstraints( DeclaringCompilation.LanguageVersion, - param.Locations(0), diagBag, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagBag, sourceModule.ContainingAssembly)) + param.GetFirstLocation(), diagBag, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagBag, sourceModule.ContainingAssembly)) End If Next @@ -434,7 +434,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If Not propertyType.IsSameTypeIgnoringAll(valueParameterType) Then If (Not propertyType.IsErrorType()) AndAlso (Not valueParameterType.IsErrorType()) Then - diagnostics.Add(ERRID.ERR_SetValueNotPropertyType, valueParameter.Locations(0)) + diagnostics.Add(ERRID.ERR_SetValueNotPropertyType, valueParameter.GetFirstLocation()) End If Else diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb index a955889e71e65..388b8de2618c7 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SourcePropertySymbol.vb @@ -119,14 +119,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If getMethod Is Nothing Then getMethod = accessorMethod Else - diagnostics.Add(ERRID.ERR_DuplicatePropertyGet, accessorMethod.Locations(0)) + diagnostics.Add(ERRID.ERR_DuplicatePropertyGet, accessorMethod.GetFirstLocation()) End If ElseIf accessorKind = SyntaxKind.SetAccessorStatement Then Dim accessorMethod = CreateAccessor(prop, SourceMemberFlags.MethodKindPropertySet, accessorFlags, bodyBinder, accessor, diagnostics) If setMethod Is Nothing Then setMethod = accessorMethod Else - diagnostics.Add(ERRID.ERR_DuplicatePropertySet, accessorMethod.Locations(0)) + diagnostics.Add(ERRID.ERR_DuplicatePropertySet, accessorMethod.GetFirstLocation()) End If End If Next @@ -145,7 +145,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(ERRID.ERR_ReadOnlyHasNoGet, location) End If If setMethod IsNot Nothing Then - diagnostics.Add(ERRID.ERR_ReadOnlyHasSet, setMethod.Locations(0)) + diagnostics.Add(ERRID.ERR_ReadOnlyHasSet, setMethod.GetFirstLocation()) End If End If @@ -158,14 +158,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(ERRID.ERR_WriteOnlyHasNoWrite, location) End If If getMethod IsNot Nothing Then - diagnostics.Add(ERRID.ERR_WriteOnlyHasGet, getMethod.Locations(0)) + diagnostics.Add(ERRID.ERR_WriteOnlyHasGet, getMethod.GetFirstLocation()) End If End If If (getMethod IsNot Nothing) AndAlso (setMethod IsNot Nothing) Then If (getMethod.LocalAccessibility <> Accessibility.NotApplicable) AndAlso (setMethod.LocalAccessibility <> Accessibility.NotApplicable) Then ' Both accessors have explicit accessibility. Report an error on the second. - Dim accessor = If(getMethod.Locations(0).SourceSpan.Start < setMethod.Locations(0).SourceSpan.Start, setMethod, getMethod) + Dim accessor = If(getMethod.GetFirstLocation().SourceSpan.Start < setMethod.GetFirstLocation().SourceSpan.Start, setMethod, getMethod) diagnostics.Add(ERRID.ERR_OnlyOneAccessorForGetSet, GetAccessorBlockBeginLocation(accessor)) ElseIf prop.IsOverridable AndAlso ((getMethod.LocalAccessibility = Accessibility.Private) OrElse (setMethod.LocalAccessibility = Accessibility.Private)) Then @@ -1248,7 +1248,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim sourceModule = DirectCast(Me.ContainingModule, SourceModuleSymbol) Dim diagnostics = BindingDiagnosticBag.GetInstance() type.CheckAllConstraints(DeclaringCompilation.LanguageVersion, - Locations(0), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) + GetFirstLocation(), diagnostics, template:=New CompoundUseSiteInfo(Of AssemblySymbol)(diagnostics, sourceModule.ContainingAssembly)) sourceModule.AtomicSetFlagAndStoreDiagnostics(_lazyState, StateFlags.TypeConstraintsChecked, 0, diagnostics) diagnostics.Free() End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventAccessorSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventAccessorSymbol.vb index 39cf890613496..9b32950a26daa 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventAccessorSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventAccessorSymbol.vb @@ -53,7 +53,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Dim parameterType As TypeSymbol If Me.MethodKind = MethodKind.EventRemove AndAlso m_propertyOrEvent.IsWindowsRuntimeEvent Then parameterType = Me.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationToken) - diagnostics.Add(Binder.GetUseSiteInfoForWellKnownType(parameterType), Me.Locations(0)) + diagnostics.Add(Binder.GetUseSiteInfoForWellKnownType(parameterType), Me.GetFirstLocation()) Else parameterType = SourceEvent.Type End If @@ -87,7 +87,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols useSiteInfo = Binder.GetUseSiteInfoForWellKnownType(type) End If - diagnostics.Add(useSiteInfo, Me.Locations(0)) + diagnostics.Add(useSiteInfo, Me.GetFirstLocation()) DirectCast(Me.ContainingModule, SourceModuleSymbol).AtomicStoreReferenceAndDiagnostics(_lazyReturnType, type, diagnostics) diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventBackingFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventBackingFieldSymbol.vb index 22493ae6c8fa7..9326acddb624f 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventBackingFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Source/SynthesizedEventBackingFieldSymbol.vb @@ -40,7 +40,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols If _propertyOrEvent.IsWindowsRuntimeEvent Then Dim tokenType = Me.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T) - diagnostics.Add(Binder.GetUseSiteInfoForWellKnownType(tokenType), _propertyOrEvent.Locations(0)) + diagnostics.Add(Binder.GetUseSiteInfoForWellKnownType(tokenType), _propertyOrEvent.GetFirstLocation()) result = tokenType.Construct(result) End If diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb index 17e8d23450c6b..275fc2026973a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb @@ -340,6 +340,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ''' Public MustOverride ReadOnly Property Locations As ImmutableArray(Of Location) + Public Function GetFirstLocation() As Location Implements ISymbolInternal.GetFirstLocation + Dim locations = Me.Locations + If locations.Length = 0 Then + Throw New InvalidOperationException("Symbol has no locations") + End If + + Return locations(0) + End Function + + Public Function GetFirstLocationOrNone() As Location Implements ISymbolInternal.GetFirstLocationOrNone + Return If(Me.Locations.IsEmpty, Location.None, GetFirstLocation()) + End Function + ''' ''' Get the syntax node(s) where this symbol was declared in source. Some symbols (for example, ''' partial classes) may be defined in more than one location. This property should return diff --git a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedEventDelegateSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedEventDelegateSymbol.vb index 9b05bcd9278d0..cb9d4e62263ea 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedEventDelegateSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedEventDelegateSymbol.vb @@ -426,7 +426,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols diagnostics.Add(New VBDiagnostic(ErrorFactory.ErrorInfo(ERRID.ERR_VariancePreventsSynthesizedEvents2, CustomSymbolDisplayFormatter.QualifiedName(outermostVariantInterface), AssociatedSymbol.Name), - Locations(0))) + GetFirstLocation())) End If DirectCast(ContainingModule, SourceModuleSymbol).AtomicStoreIntegerAndDiagnostics(_reportedAllDeclarationErrors, 1, 0, diagnostics) diff --git a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Rewriters/LocalDeclarationRewriter.cs b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Rewriters/LocalDeclarationRewriter.cs index 83cf9a18f6d6c..7a062b36d97e7 100644 --- a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Rewriters/LocalDeclarationRewriter.cs +++ b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Rewriters/LocalDeclarationRewriter.cs @@ -97,7 +97,7 @@ private static void CreateLocal( var method = PlaceholderLocalSymbol.GetIntrinsicMethod(compilation, ExpressionCompilerConstants.CreateVariableMethodName); if ((object)method == null) { - diagnostics.Add(ErrorCode.ERR_DeclarationExpressionNotPermitted, local.Locations[0]); + diagnostics.Add(ErrorCode.ERR_DeclarationExpressionNotPermitted, local.GetFirstLocation()); return; } diff --git a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs index 64de64dcd3779..e9ed78e02f952 100644 --- a/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs +++ b/src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/EEMethodSymbol.cs @@ -500,7 +500,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState, this.CalculateUseSiteDiagnostic(ref useSiteInfo); if (useSiteInfo.DiagnosticInfo != null && useSiteInfo.DiagnosticInfo.Severity == DiagnosticSeverity.Error) { - diagnostics.Add(useSiteInfo.DiagnosticInfo, this.Locations[0]); + diagnostics.Add(useSiteInfo.DiagnosticInfo, this.GetFirstLocation()); return; } @@ -524,7 +524,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState, var name = local.Name; if (name.StartsWith("$", StringComparison.Ordinal)) { - diagnostics.Add(ErrorCode.ERR_UnexpectedCharacter, local.Locations[0], name[0]); + diagnostics.Add(ErrorCode.ERR_UnexpectedCharacter, local.GetFirstLocation(), name[0]); return; } }