Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static void checkCollisions(IEnumerable<SourceNamedTypeSymbol> extensions, Func<
alreadyReportedExtensions ??= PooledHashSet<SourceNamedTypeSymbol>.GetInstance();
if (alreadyReportedExtensions.Add(extension))
{
diagnostics.Add(ErrorCode.ERR_ExtensionBlockCollision, extension.Locations[0]);
diagnostics.Add(ErrorCode.ERR_ExtensionBlockCollision, extension.GetFirstLocation());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/PEWriter/MetadataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/Core/Portable/Symbols/ISymbolInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ internal interface ISymbolInternal
/// </summary>
bool IsDefinition { get; }

Location GetFirstLocation();
Location GetFirstLocationOrNone();

/// <summary>
/// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/VisualBasic/Portable/Binding/Binder_Lambda.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -142,7 +142,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
unboundType,
unboundParam.IsByRef,
unboundParam.Syntax,
unboundParam.Locations(0))
unboundParam.GetFirstLocation())
Next
End If

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions src/Compilers/VisualBasic/Portable/Compilation/MethodCompiler.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading