Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<NoWarn>$(NoWarn);VSIXCompatibility1001</NoWarn>

<!-- TODO: https://github.com/dotnet/roslyn/issues/71667 -->
<NoWarn>$(NoWarn);NU1507;NU1510</NoWarn>
<NoWarn>$(NoWarn);NU1507</NoWarn>

<CommonExtensionInstallationRoot>CommonExtensions</CommonExtensionInstallationRoot>
<LanguageServicesExtensionInstallationFolder>Microsoft\VBCSharp\LanguageServices</LanguageServicesExtensionInstallationFolder>
Expand Down
6 changes: 3 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"sdk": {
"version": "10.0.100-preview.5.25277.114",
"version": "9.0.106",
"allowPrerelease": false,
"rollForward": "patch"
},
"tools": {
"dotnet": "10.0.100-preview.5.25277.114",
"dotnet": "9.0.106",
"vs": {
"version": "17.14.0"
"version": "17.8.0"
},
"vswhere": "3.1.7"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed partial class CSharpUseCollectionExpressionForBuilderDiagnosticA
EnforceOnBuildValues.UseCollectionExpressionForBuilder)
{
private const string CreateBuilderName = nameof(ImmutableArray.CreateBuilder);
private const string GetInstanceName = nameof(ArrayBuilder<>.GetInstance);
private const string GetInstanceName = nameof(ArrayBuilder<int>.GetInstance);

protected override void InitializeWorker(CodeBlockStartAnalysisContext<SyntaxKind> context, INamedTypeSymbol? expressionType)
=> context.RegisterSyntaxNodeAction(context => AnalyzeInvocationExpression(context, expressionType), SyntaxKind.InvocationExpression);
Expand Down Expand Up @@ -117,7 +117,7 @@ void FadeOutCode(SyntaxNodeAnalysisContext context, AnalysisResult analysisResul
return null;

if (memberAccessExpression.Name.Identifier.ValueText == GetInstanceName &&
memberAccessExpression.Expression is not GenericNameSyntax { Identifier.ValueText: nameof(ArrayBuilder<>) })
memberAccessExpression.Expression is not GenericNameSyntax { Identifier.ValueText: nameof(ArrayBuilder<int>) })
{
return null;
}
Expand Down Expand Up @@ -217,12 +217,12 @@ identifierName.Parent is MemberAccessExpressionSyntax(SyntaxKind.SimpleMemberAcc
memberAccess.Expression == identifierName &&
memberAccess.Parent is InvocationExpressionSyntax { ArgumentList.Arguments.Count: 0 } invocationExpression &&
memberAccess.Name.Identifier.ValueText
is nameof(ImmutableArray<>.Builder.ToImmutable)
or nameof(ImmutableArray<>.Builder.MoveToImmutable)
or nameof(ImmutableArray<>.Builder.ToArray)
or nameof(ArrayBuilder<>.ToImmutableAndClear)
or nameof(ArrayBuilder<>.ToImmutableAndFree)
or nameof(ArrayBuilder<>.ToArrayAndFree)
is nameof(ImmutableArray<int>.Builder.ToImmutable)
or nameof(ImmutableArray<int>.Builder.MoveToImmutable)
or nameof(ImmutableArray<int>.Builder.ToArray)
or nameof(ArrayBuilder<int>.ToImmutableAndClear)
or nameof(ArrayBuilder<int>.ToImmutableAndFree)
or nameof(ArrayBuilder<int>.ToArrayAndFree)
or nameof(Enumerable.ToList))
{
return invocationExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ internal sealed partial class CSharpUseCollectionExpressionForFluentDiagnosticAn
private static readonly ImmutableArray<string> s_suffixes =
[
nameof(Array),
nameof(Span<>),
nameof(ReadOnlySpan<>),
nameof(System.Collections.Generic.List<>),
nameof(HashSet<>),
nameof(LinkedList<>),
nameof(Queue<>),
nameof(SortedSet<>),
nameof(Stack<>),
nameof(ICollection<>),
nameof(IReadOnlyCollection<>),
nameof(IList<>),
nameof(IReadOnlyList<>),
nameof(ImmutableArray<>),
nameof(ImmutableHashSet<>),
nameof(ImmutableList<>),
nameof(ImmutableQueue<>),
nameof(ImmutableSortedSet<>),
nameof(ImmutableStack<>),
nameof(Span<int>),
nameof(ReadOnlySpan<int>),
nameof(System.Collections.Generic.List<int>),
nameof(HashSet<int>),
nameof(LinkedList<int>),
nameof(Queue<int>),
nameof(SortedSet<int>),
nameof(Stack<int>),
nameof(ICollection<int>),
nameof(IReadOnlyCollection<int>),
nameof(IList<int>),
nameof(IReadOnlyList<int>),
nameof(ImmutableArray<int>),
nameof(ImmutableHashSet<int>),
nameof(ImmutableList<int>),
nameof(ImmutableQueue<int>),
nameof(ImmutableSortedSet<int>),
nameof(ImmutableStack<int>),
nameof(System.Collections.Immutable),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void AnalyzeBaseObjectCreationExpression(

var symbol = semanticModel.GetSymbolInfo(objectCreationExpression, cancellationToken).Symbol;
if (symbol is not IMethodSymbol { MethodKind: MethodKind.Constructor, Parameters: [var constructorParameter] } ||
constructorParameter.Type.Name != nameof(IEnumerable<>))
constructorParameter.Type.Name != nameof(IEnumerable<int>))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ bool IsSafeConversionWhenTypesDoNotMatch(out bool changesSemantics)
var convertedType = originalTypeInfo.ConvertedType;

var convertedToReadOnlySpan =
convertedType.Name == nameof(ReadOnlySpan<>) &&
convertedType.Name == nameof(ReadOnlySpan<int>) &&
convertedType.OriginalDefinition.Equals(compilation.ReadOnlySpanOfTType());

var convertedToSpan =
convertedType.Name == nameof(Span<>) &&
convertedType.Name == nameof(Span<int>) &&
convertedType.OriginalDefinition.Equals(compilation.SpanOfTType());

// ReadOnlySpan<X> x = stackalloc[] ...
Expand All @@ -206,7 +206,7 @@ bool IsSafeConversionWhenTypesDoNotMatch(out bool changesSemantics)
// restrictive than Span<X>
var isSpanToReadOnlySpan =
convertedToReadOnlySpan &&
type.Name == nameof(Span<>) &&
type.Name == nameof(Span<int>) &&
type.OriginalDefinition.Equals(compilation.SpanOfTType()) &&
convertedType.GetTypeArguments()[0].Equals(type.GetTypeArguments()[0]);
if (isSpanToReadOnlySpan)
Expand Down Expand Up @@ -264,7 +264,7 @@ bool IsSafeConversionWhenTypesDoNotMatch(out bool changesSemantics)
// disallow converting those types to ensure semantics are preserved. We do this even though
// allowSemanticsChange is true because this will basically be certain to break semantics, as opposed to
// the more common case where semantics may change slightly, but likely not in a way that breaks code.
if (type.Name is nameof(ObservableCollection<>) or nameof(ReadOnlyObservableCollection<>))
if (type.Name is nameof(ObservableCollection<int>) or nameof(ReadOnlyObservableCollection<int>))
return false;

// If the original expression was creating a set, but is being assigned to one of the well known
Expand Down Expand Up @@ -933,7 +933,7 @@ bool IsCompatibleSignatureAndArguments(
{
Type: INamedTypeSymbol
{
Name: nameof(IEnumerable<>),
Name: nameof(IEnumerable<int>),
TypeArguments: [ITypeParameterSymbol { TypeParameterKind: TypeParameterKind.Method }]
} enumerableType
}] &&
Expand Down Expand Up @@ -980,7 +980,7 @@ originalCreateMethod.Parameters is [
{
Type: INamedTypeSymbol
{
Name: nameof(Span<>) or nameof(ReadOnlySpan<>),
Name: nameof(Span<int>) or nameof(ReadOnlySpan<int>),
TypeArguments: [ITypeParameterSymbol { TypeParameterKind: TypeParameterKind.Method }]
} spanType
}])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private MemberInfo ComputeMemberInfo(IMethodSymbol sliceLikeMethod, bool require
// Also, look to see if the type has a `.Slice(int start, int length)` method.
// This is also a method the compiler knows to look for when a user writes `x[a..b]`
var actualSliceMethod =
sliceLikeMethod.ContainingType.GetMembers(nameof(Span<>.Slice))
sliceLikeMethod.ContainingType.GetMembers(nameof(Span<int>.Slice))
.OfType<IMethodSymbol>()
.FirstOrDefault(s => IsTwoArgumentSliceLikeMethod(s));
if (actualSliceMethod != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ private static TypeSyntax FixMethodReturnType(
if (IsIEnumerable(returnType, knownTypes) && IsIterator(methodSymbol, cancellationToken))
{
newReturnType = knownTypes.IAsyncEnumerableOfTType is null
? MakeGenericType(nameof(IAsyncEnumerable<>), methodSymbol.ReturnType)
? MakeGenericType(nameof(IAsyncEnumerable<int>), methodSymbol.ReturnType)
: knownTypes.IAsyncEnumerableOfTType.Construct(methodSymbol.ReturnType.GetTypeArguments()[0]).GenerateTypeSyntax();
}
else if (IsIEnumerator(returnType, knownTypes) && IsIterator(methodSymbol, cancellationToken))
{
newReturnType = knownTypes.IAsyncEnumeratorOfTType is null
? MakeGenericType(nameof(IAsyncEnumerator<>), methodSymbol.ReturnType)
? MakeGenericType(nameof(IAsyncEnumerator<int>), methodSymbol.ReturnType)
: knownTypes.IAsyncEnumeratorOfTType.Construct(methodSymbol.ReturnType.GetTypeArguments()[0]).GenerateTypeSyntax();
}
else if (IsIAsyncEnumerableOrEnumerator(returnType, knownTypes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static ExpressionSyntax CreateUtf8String(SyntaxTriviaList leadingTrivia,
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
stringLiteral,
IdentifierName(nameof(ReadOnlySpan<>.ToArray))))
IdentifierName(nameof(ReadOnlySpan<byte>.ToArray))))
.WithTrailingTrivia(trailingTrivia);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ namespace Microsoft.CodeAnalysis.Shared.Utilities;
/// </summary>
internal readonly partial struct HashCodeAnalyzer
{
private readonly Compilation _compilation;
private readonly IMethodSymbol _objectGetHashCodeMethod;
private readonly INamedTypeSymbol? _equalityComparerType;

public readonly INamedTypeSymbol SystemHashCodeType;

private HashCodeAnalyzer(
IMethodSymbol objectGetHashCodeMethod,
Compilation compilation, IMethodSymbol objectGetHashCodeMethod,
INamedTypeSymbol? equalityComparerType, INamedTypeSymbol systemHashCodeType)
{
_compilation = compilation;
_objectGetHashCodeMethod = objectGetHashCodeMethod;
_equalityComparerType = equalityComparerType;
SystemHashCodeType = systemHashCodeType;
Expand All @@ -45,7 +47,7 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
if (systemHashCodeType == null)
return false;

analyzer = new HashCodeAnalyzer(objectGetHashCodeMethod, equalityComparerType, systemHashCodeType);
analyzer = new HashCodeAnalyzer(compilation, objectGetHashCodeMethod, equalityComparerType, systemHashCodeType);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
syntaxFacts.GetPartsOfMemberAccessExpression(conditionMemberAccess, out var conditionExpression, out var conditionSimpleName);
syntaxFacts.GetNameAndArityOfSimpleName(conditionSimpleName, out var conditionName, out _);

if (conditionName != nameof(Nullable<>.HasValue))
if (conditionName != nameof(Nullable<int>.HasValue))
return;

var whenPartToCheck = notHasValueExpression ? whenFalseNodeLow : whenTrueNodeLow;
Expand All @@ -90,7 +90,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
syntaxFacts.GetPartsOfMemberAccessExpression(whenPartMemberAccess, out var whenPartExpression, out var whenPartSimpleName);
syntaxFacts.GetNameAndArityOfSimpleName(whenPartSimpleName, out var whenPartName, out _);

if (whenPartName != nameof(Nullable<>.Value))
if (whenPartName != nameof(Nullable<int>.Value))
return;

if (!syntaxFacts.AreEquivalent(conditionExpression, whenPartExpression))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal readonly struct UpdateExpressionState<
{
private static readonly ImmutableArray<(string name, bool isLinq)> s_multiAddNames =
[
(nameof(List<>.AddRange), isLinq: false),
(nameof(List<int>.AddRange), isLinq: false),
(nameof(Enumerable.Concat), isLinq: true),
(nameof(Enumerable.Append), isLinq: true),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class UseNullPropagationHelpers
public static bool IsSystemNullableValueProperty([NotNullWhen(true)] ISymbol? symbol)
=> symbol is
{
Name: nameof(Nullable<>.Value),
Name: nameof(Nullable<int>.Value),
ContainingType.OriginalDefinition.SpecialType: SpecialType.System_Nullable_T,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
{
if (context.Diagnostics.First().Properties.ContainsKey(ForEachCastHelpers.IsFixable))
{
RegisterCodeFix(context, AnalyzersResources.Add_explicit_cast, nameof(AbstractForEachCastCodeFixProvider<>));
RegisterCodeFix(context, AnalyzersResources.Add_explicit_cast, nameof(AbstractForEachCastCodeFixProvider<SyntaxNode>));
}

return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private bool TryInitializeSimpleName(
{
// If we inferred Func/Action here, attempt to create better parameter names than the default
// 'arg1/arg2/arg3' form that the delegate specifies.
var parameterNames = delegateInvokeMethod.ContainingType is { Name: nameof(Action) or nameof(Func<>), ContainingNamespace.Name: nameof(System) }
var parameterNames = delegateInvokeMethod.ContainingType is { Name: nameof(Action) or nameof(Func<int>), ContainingNamespace.Name: nameof(System) }
? GenerateParameterNamesBasedOnParameterTypes(delegateInvokeMethod.Parameters)
: delegateInvokeMethod.Parameters.SelectAsArray(p => p.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private void FixIfStatement(
syntaxFacts.GetNameAndArityOfSimpleName(nameNode, out var name, out var arity);
var comparer = syntaxFacts.StringComparer;

if (arity == 0 && comparer.Equals(name, nameof(Nullable<>.Value)))
if (arity == 0 && comparer.Equals(name, nameof(Nullable<int>.Value)))
{
// They're calling ".Value" off of a nullable. Because we're moving to ?.
// we want to remove the .Value as well. i.e. we should generate:
Expand Down
3 changes: 0 additions & 3 deletions src/Compilers/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ dotnet_diagnostic.RS0100.severity = none
# RS0102: Braces must not have blank lines between them
dotnet_diagnostic.RS0102.severity = none

# IDE0051: Unused member
dotnet_diagnostic.IDE0051.severity = none

# IDE0170: Prefer extended property pattern
dotnet_diagnostic.IDE0170.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ when ConvertExpressionToType(expr, out var leftType):
default:
type = null;
return false;
}
};
}

private PatternSyntax ParsePattern(Precedence precedence, bool afterIs = false, bool inSwitchArmPattern = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void ScanRawStringLiteral(ref TokenInfo info, bool inDirective)

default:
throw ExceptionUtilities.UnexpectedValue(info.Kind);
}
};
}

info.Text = TextWindow.GetText(intern: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4126,7 +4126,7 @@ static void Main()
if (isFromMetadata)
{
VerifyParamArrayAttribute(parameterB);
}
};
};

var verifier = CompileAndVerify(source, symbolValidator: validator(true), sourceSymbolValidator: validator(false), expectedOutput: @"System.Int32[]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void SimpleDelegateMembersTest(string ob, string cb)
GetMember<NamedTypeSymbol>("voidDelegate").GetMembers().ToArray();

AssertEx.SetEqual(actualMembers.Select(s => s.Name), expectedMembers);
}
};
};

VerifyType verify = (winmd, expected) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ void validate(ModuleSymbol module)
AssertDeclaresType(peModule, WellKnownType.System_Runtime_CompilerServices_IsByRefLikeAttribute, Accessibility.Public);
AssertHasCompilerFeatureRequired(includeCompilerFeatureRequired, peType, peModule, new MetadataDecoder(peModule));
}
}
};

CompileAndVerify(new[] { text, GetCompilerFeatureRequiredAttributeText(includeCompilerFeatureRequired) }, verify: Verification.Passes, symbolValidator: validate, sourceSymbolValidator: validate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5752,7 +5752,7 @@ void metadataValidator(ModuleSymbol module)

Assert.Equal(new[] { "CompilerGeneratedAttribute" }, GetAttributeNames(method.GetAttributes()));
Assert.True(method.RequiresSecurityObject);
}
};

var verifier = CompileAndVerify(
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static void validate(ModuleSymbol module)
Assert.Equal(0, m.OverloadResolutionPriority);
}
}
}
};
}

[Theory, CombinatorialData]
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/Core/Portable/EmbeddedText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public override void WriteByte(byte value)
base.WriteByte(value);

// same rationale for checked arithmetic as above.
checked { BytesWritten++; }
checked { BytesWritten++; };
}

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Expand Down
13 changes: 13 additions & 0 deletions src/Compilers/Core/Portable/MetadataReader/PEModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,19 @@ private static bool CrackBoolAndStringInAttributeValue(out BoolAndStringData val
return false;
}

private static bool CrackBoolAndBoolInAttributeValue(out (bool, bool) value, ref BlobReader sig)
{
if (CrackBooleanInAttributeValue(out bool item1, ref sig) &&
CrackBooleanInAttributeValue(out bool item2, ref sig))
{
value = (item1, item2);
return true;
}

value = default;
return false;
}

private static bool CrackBooleanInAttributeValue(out bool value, ref BlobReader sig)
{
if (sig.RemainingBytes >= 1)
Expand Down
Loading