未验证 提交 113f3932 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #40493 from jaredpar/nullable3

Nullable annotations for Compilation
......@@ -28,8 +28,8 @@
"type": "shell",
"args": [
"msbuild",
"src/Compilers/CSharp/csc/csc.csproj",
"-p:UseRoslynAnalyzers=false"
"-p:UseRoslynAnalyzers=false",
"src/Compilers/CSharp/csc/csc.csproj"
],
"problemMatcher": "$msCompile",
"group": "build"
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace Microsoft.CodeAnalysis
......@@ -33,7 +36,7 @@ internal class ModuleCompilationState<TNamedTypeSymbol, TMethodSymbol> : CommonM
/// <summary>
/// Maps an async/iterator method to the synthesized state machine type that implements the method.
/// </summary>
private Dictionary<TMethodSymbol, TNamedTypeSymbol> _lazyStateMachineTypes;
private Dictionary<TMethodSymbol, TNamedTypeSymbol>? _lazyStateMachineTypes;
internal void SetStateMachineType(TMethodSymbol method, TNamedTypeSymbol stateMachineClass)
{
......@@ -50,7 +53,7 @@ internal void SetStateMachineType(TMethodSymbol method, TNamedTypeSymbol stateMa
}
}
internal bool TryGetStateMachineType(TMethodSymbol method, out TNamedTypeSymbol stateMachineType)
internal bool TryGetStateMachineType(TMethodSymbol method, [NotNullWhen(true)] out TNamedTypeSymbol? stateMachineType)
{
Debug.Assert(Frozen);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -29,7 +31,7 @@ public abstract class CompilationOptions
/// is derived from the name of the compilation (<see cref="Compilation.AssemblyName"/>)
/// by appending a default extension for <see cref="OutputKind"/>.
/// </remarks>
public string ModuleName { get; protected set; }
public string? ModuleName { get; protected set; }
/// <summary>
/// The full name of a global implicit class (script class). This class implicitly encapsulates top-level statements,
......@@ -41,7 +43,7 @@ public abstract class CompilationOptions
/// The full name of a type that declares static Main method. Must be a valid non-generic namespace-qualified name.
/// Null if any static Main method is a candidate for an entry point.
/// </summary>
public string MainTypeName { get; protected set; }
public string? MainTypeName { get; protected set; }
// Note that we avoid using default(ImmutableArray<byte>) for unspecified value since
// such value is currently not serializable by JSON serializer.
......@@ -70,7 +72,7 @@ public abstract class CompilationOptions
/// path to key file.
/// </para>
/// </remarks>
public string CryptoKeyFile { get; protected set; }
public string? CryptoKeyFile { get; protected set; }
/// <summary>
/// The CSP container containing the key with which to sign the output.
......@@ -86,7 +88,7 @@ public abstract class CompilationOptions
/// a signing tool (Microsoft .NET Framework Strong Name Utility (sn.exe) or equivalent) to sign them.
/// </para>
/// </remarks>
public string CryptoKeyContainer { get; protected set; }
public string? CryptoKeyContainer { get; protected set; }
/// <summary>
/// Mark the compilation assembly as delay-signed.
......@@ -207,25 +209,25 @@ public abstract class CompilationOptions
/// Resolves paths to metadata references specified in source via #r directives.
/// Null if the compilation can't contain references to metadata other than those explicitly passed to its factory (such as #r directives in sources).
/// </summary>
public MetadataReferenceResolver MetadataReferenceResolver { get; protected set; }
public MetadataReferenceResolver? MetadataReferenceResolver { get; protected set; }
/// <summary>
/// Gets the resolver for resolving XML document references for the compilation.
/// Null if the compilation is not allowed to contain XML file references, such as XML doc comment include tags and permission sets stored in an XML file.
/// </summary>
public XmlReferenceResolver XmlReferenceResolver { get; protected set; }
public XmlReferenceResolver? XmlReferenceResolver { get; protected set; }
/// <summary>
/// Gets the resolver for resolving source document references for the compilation.
/// Null if the compilation is not allowed to contain source file references, such as #line pragmas and #load directives.
/// </summary>
public SourceReferenceResolver SourceReferenceResolver { get; protected set; }
public SourceReferenceResolver? SourceReferenceResolver { get; protected set; }
/// <summary>
/// Provides strong name and signature the source assembly.
/// Null if assembly signing is not supported.
/// </summary>
public StrongNameProvider StrongNameProvider { get; protected set; }
public StrongNameProvider? StrongNameProvider { get; protected set; }
/// <summary>
/// Used to compare assembly identities. May implement unification and portability policies specific to the target platform.
......@@ -264,11 +266,11 @@ protected set
internal CompilationOptions(
OutputKind outputKind,
bool reportSuppressedDiagnostics,
string moduleName,
string mainTypeName,
string scriptClassName,
string cryptoKeyContainer,
string cryptoKeyFile,
string? moduleName,
string? mainTypeName,
string? scriptClassName,
string? cryptoKeyContainer,
string? cryptoKeyFile,
ImmutableArray<byte> cryptoPublicKey,
bool? delaySign,
bool publicSign,
......@@ -282,11 +284,11 @@ protected set
bool deterministic,
DateTime currentLocalTime,
bool debugPlusMode,
XmlReferenceResolver xmlReferenceResolver,
SourceReferenceResolver sourceReferenceResolver,
MetadataReferenceResolver metadataReferenceResolver,
XmlReferenceResolver? xmlReferenceResolver,
SourceReferenceResolver? sourceReferenceResolver,
MetadataReferenceResolver? metadataReferenceResolver,
AssemblyIdentityComparer assemblyIdentityComparer,
StrongNameProvider strongNameProvider,
StrongNameProvider? strongNameProvider,
MetadataImportOptions metadataImportOptions,
bool referencesSupersedeLowerVersions)
{
......@@ -448,17 +450,17 @@ public CompilationOptions WithOptimizationLevel(OptimizationLevel value)
return CommonWithOptimizationLevel(value);
}
public CompilationOptions WithXmlReferenceResolver(XmlReferenceResolver resolver)
public CompilationOptions WithXmlReferenceResolver(XmlReferenceResolver? resolver)
{
return CommonWithXmlReferenceResolver(resolver);
}
public CompilationOptions WithSourceReferenceResolver(SourceReferenceResolver resolver)
public CompilationOptions WithSourceReferenceResolver(SourceReferenceResolver? resolver)
{
return CommonWithSourceReferenceResolver(resolver);
}
public CompilationOptions WithMetadataReferenceResolver(MetadataReferenceResolver resolver)
public CompilationOptions WithMetadataReferenceResolver(MetadataReferenceResolver? resolver)
{
return CommonWithMetadataReferenceResolver(resolver);
}
......@@ -468,17 +470,17 @@ public CompilationOptions WithAssemblyIdentityComparer(AssemblyIdentityComparer
return CommonWithAssemblyIdentityComparer(comparer);
}
public CompilationOptions WithStrongNameProvider(StrongNameProvider provider)
public CompilationOptions WithStrongNameProvider(StrongNameProvider? provider)
{
return CommonWithStrongNameProvider(provider);
}
public CompilationOptions WithModuleName(string moduleName)
public CompilationOptions WithModuleName(string? moduleName)
{
return CommonWithModuleName(moduleName);
}
public CompilationOptions WithMainTypeName(string mainTypeName)
public CompilationOptions WithMainTypeName(string? mainTypeName)
{
return CommonWithMainTypeName(mainTypeName);
}
......@@ -488,7 +490,7 @@ public CompilationOptions WithScriptClassName(string scriptClassName)
return CommonWithScriptClassName(scriptClassName);
}
public CompilationOptions WithCryptoKeyContainer(string cryptoKeyContainer)
public CompilationOptions WithCryptoKeyContainer(string? cryptoKeyContainer)
{
return CommonWithCryptoKeyContainer(cryptoKeyContainer);
}
......@@ -521,19 +523,19 @@ public CompilationOptions WithOverflowChecks(bool checkOverflow)
protected abstract CompilationOptions CommonWithPlatform(Platform platform);
protected abstract CompilationOptions CommonWithPublicSign(bool publicSign);
protected abstract CompilationOptions CommonWithOptimizationLevel(OptimizationLevel value);
protected abstract CompilationOptions CommonWithXmlReferenceResolver(XmlReferenceResolver resolver);
protected abstract CompilationOptions CommonWithSourceReferenceResolver(SourceReferenceResolver resolver);
protected abstract CompilationOptions CommonWithMetadataReferenceResolver(MetadataReferenceResolver resolver);
protected abstract CompilationOptions CommonWithXmlReferenceResolver(XmlReferenceResolver? resolver);
protected abstract CompilationOptions CommonWithSourceReferenceResolver(SourceReferenceResolver? resolver);
protected abstract CompilationOptions CommonWithMetadataReferenceResolver(MetadataReferenceResolver? resolver);
protected abstract CompilationOptions CommonWithAssemblyIdentityComparer(AssemblyIdentityComparer comparer);
protected abstract CompilationOptions CommonWithStrongNameProvider(StrongNameProvider provider);
protected abstract CompilationOptions CommonWithStrongNameProvider(StrongNameProvider? provider);
protected abstract CompilationOptions CommonWithGeneralDiagnosticOption(ReportDiagnostic generalDiagnosticOption);
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithSpecificDiagnosticOptions(IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions);
protected abstract CompilationOptions CommonWithReportSuppressedDiagnostics(bool reportSuppressedDiagnostics);
protected abstract CompilationOptions CommonWithModuleName(string moduleName);
protected abstract CompilationOptions CommonWithMainTypeName(string mainTypeName);
protected abstract CompilationOptions CommonWithModuleName(string? moduleName);
protected abstract CompilationOptions CommonWithMainTypeName(string? mainTypeName);
protected abstract CompilationOptions CommonWithScriptClassName(string scriptClassName);
protected abstract CompilationOptions CommonWithCryptoKeyContainer(string cryptoKeyContainer);
protected abstract CompilationOptions CommonWithCryptoKeyContainer(string? cryptoKeyContainer);
protected abstract CompilationOptions CommonWithCryptoKeyFile(string cryptoKeyFile);
protected abstract CompilationOptions CommonWithCryptoPublicKey(ImmutableArray<byte> cryptoPublicKey);
protected abstract CompilationOptions CommonWithDelaySign(bool? delaySign);
......@@ -672,12 +674,12 @@ protected int GetHashCodeHelper()
Hash.Combine((int)this.NullableContextOptions, 0)))))))))))))))))))))))))));
}
public static bool operator ==(CompilationOptions left, CompilationOptions right)
public static bool operator ==(CompilationOptions? left, CompilationOptions? right)
{
return object.Equals(left, right);
}
public static bool operator !=(CompilationOptions left, CompilationOptions right)
public static bool operator !=(CompilationOptions? left, CompilationOptions? right)
{
return !object.Equals(left, right);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Immutable;
using System.Diagnostics;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis.Operations
{
internal class Expression
......@@ -38,7 +40,7 @@ public static ConstantValue SynthesizeNumeric(ITypeSymbol type, int value)
if (type.TypeKind == TypeKind.Enum)
{
return SynthesizeNumeric(((INamedTypeSymbol)type).EnumUnderlyingType, value);
return SynthesizeNumeric(((INamedTypeSymbol)type).EnumUnderlyingType!, value);
}
return ConstantValue.Bad;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -8,16 +10,16 @@
namespace Microsoft.CodeAnalysis
{
internal struct LoadDirective : IEquatable<LoadDirective>
internal readonly struct LoadDirective : IEquatable<LoadDirective>
{
public readonly string ResolvedPath;
public readonly string? ResolvedPath;
public readonly ImmutableArray<Diagnostic> Diagnostics;
public LoadDirective(string resolvedPath, ImmutableArray<Diagnostic> diagnostics)
public LoadDirective(string? resolvedPath, ImmutableArray<Diagnostic> diagnostics)
{
Debug.Assert((resolvedPath != null) || !diagnostics.IsEmpty);
Debug.Assert(!diagnostics.IsDefault);
Debug.Assert(diagnostics.IsEmpty || diagnostics.All(d => d.Severity == DiagnosticSeverity.Error));
RoslynDebug.Assert((resolvedPath != null) || !diagnostics.IsEmpty);
RoslynDebug.Assert(!diagnostics.IsDefault);
RoslynDebug.Assert(diagnostics.IsEmpty || diagnostics.All(d => d.Severity == DiagnosticSeverity.Error));
ResolvedPath = resolvedPath;
Diagnostics = diagnostics;
......@@ -36,7 +38,7 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
return Hash.Combine(this.Diagnostics.GetHashCode(), this.ResolvedPath.GetHashCode());
return Hash.Combine(this.Diagnostics.GetHashCode(), this.ResolvedPath?.GetHashCode() ?? 0);
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Diagnostics;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -127,9 +129,9 @@ public ParseOptions WithFeatures(IEnumerable<KeyValuePair<string, string>> featu
/// </summary>
public abstract IEnumerable<string> PreprocessorSymbolNames { get; }
public abstract override bool Equals(object obj);
public abstract override bool Equals(object? obj);
protected bool EqualsHelper(ParseOptions other)
protected bool EqualsHelper(ParseOptions? other)
{
if (object.ReferenceEquals(other, null))
{
......@@ -166,12 +168,12 @@ private static int HashFeatures(IReadOnlyDictionary<string, string> features)
return value;
}
public static bool operator ==(ParseOptions left, ParseOptions right)
public static bool operator ==(ParseOptions? left, ParseOptions? right)
{
return object.Equals(left, right);
}
public static bool operator !=(ParseOptions left, ParseOptions right)
public static bool operator !=(ParseOptions? left, ParseOptions? right)
{
return !object.Equals(left, right);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
public enum Platform
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Roslyn.Utilities;
using System;
......@@ -12,14 +14,14 @@ public struct PreprocessingSymbolInfo : IEquatable<PreprocessingSymbolInfo>
/// <summary>
/// The symbol that was referred to by the identifier, if any.
/// </summary>
public IPreprocessingSymbol Symbol { get; }
public IPreprocessingSymbol? Symbol { get; }
/// <summary>
/// Returns true if this preprocessing symbol is defined at the identifier position.
/// </summary>
public bool IsDefined { get; }
internal PreprocessingSymbolInfo(IPreprocessingSymbol symbol, bool isDefined)
internal PreprocessingSymbolInfo(IPreprocessingSymbol? symbol, bool isDefined)
: this()
{
this.Symbol = symbol;
......@@ -34,7 +36,7 @@ public bool Equals(PreprocessingSymbolInfo other)
public override bool Equals(object obj)
{
return obj is PreprocessingSymbolInfo && this.Equals((PreprocessingSymbolInfo)obj);
return obj is PreprocessingSymbolInfo p && this.Equals(p);
}
public override int GetHashCode()
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
{
public abstract class ScriptCompilationInfo
{
internal Type ReturnTypeOpt { get; }
internal Type? ReturnTypeOpt { get; }
public Type ReturnType => ReturnTypeOpt ?? typeof(object);
public Type GlobalsType { get; }
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -72,7 +74,7 @@ public SyntaxTree SyntaxTree
/// <param name="node">The expression or statement syntax node.</param>
/// <param name="cancellationToken">An optional cancellation token.</param>
/// <returns></returns>
public IOperation GetOperation(SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
public IOperation? GetOperation(SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
......@@ -457,8 +459,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </remarks>
public ImmutableArray<ISymbol> LookupSymbols(
int position,
INamespaceOrTypeSymbol container = null,
string name = null,
INamespaceOrTypeSymbol? container = null,
string? name = null,
bool includeReducedExtensionMethods = false)
{
return LookupSymbolsCore(position, container, name, includeReducedExtensionMethods);
......@@ -469,8 +471,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </summary>
protected abstract ImmutableArray<ISymbol> LookupSymbolsCore(
int position,
INamespaceOrTypeSymbol container,
string name,
INamespaceOrTypeSymbol? container,
string? name,
bool includeReducedExtensionMethods);
/// <summary>
......@@ -510,7 +512,7 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </remarks>
public ImmutableArray<ISymbol> LookupBaseMembers(
int position,
string name = null)
string? name = null)
{
return LookupBaseMembersCore(position, name);
}
......@@ -520,7 +522,7 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </summary>
protected abstract ImmutableArray<ISymbol> LookupBaseMembersCore(
int position,
string name);
string? name);
/// <summary>
/// Gets the available named static member symbols in the context of the specified location and optional container.
......@@ -544,8 +546,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </remarks>
public ImmutableArray<ISymbol> LookupStaticMembers(
int position,
INamespaceOrTypeSymbol container = null,
string name = null)
INamespaceOrTypeSymbol? container = null,
string? name = null)
{
return LookupStaticMembersCore(position, container, name);
}
......@@ -555,8 +557,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </summary>
protected abstract ImmutableArray<ISymbol> LookupStaticMembersCore(
int position,
INamespaceOrTypeSymbol container,
string name);
INamespaceOrTypeSymbol? container,
string? name);
/// <summary>
/// Gets the available named namespace and type symbols in the context of the specified location and optional container.
......@@ -578,8 +580,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </remarks>
public ImmutableArray<ISymbol> LookupNamespacesAndTypes(
int position,
INamespaceOrTypeSymbol container = null,
string name = null)
INamespaceOrTypeSymbol? container = null,
string? name = null)
{
return LookupNamespacesAndTypesCore(position, container, name);
}
......@@ -589,8 +591,8 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </summary>
protected abstract ImmutableArray<ISymbol> LookupNamespacesAndTypesCore(
int position,
INamespaceOrTypeSymbol container,
string name);
INamespaceOrTypeSymbol? container,
string? name);
/// <summary>
/// Gets the available named label symbols in the context of the specified location and optional container.
......@@ -608,7 +610,7 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </remarks>
public ImmutableArray<ISymbol> LookupLabels(
int position,
string name = null)
string? name = null)
{
return LookupLabelsCore(position, name);
}
......@@ -618,7 +620,7 @@ internal ImmutableArray<ISymbol> GetDeclaredSymbolsForNode(SyntaxNode declaratio
/// </summary>
protected abstract ImmutableArray<ISymbol> LookupLabelsCore(
int position,
string name);
string? name);
/// <summary>
/// Analyze control-flow within a part of a method body.
......
......@@ -27,7 +27,7 @@ protected SourceReferenceResolver()
/// <param name="path">The source path to normalize. May be absolute or relative.</param>
/// <param name="baseFilePath">Path of the source file that contains the <paramref name="path"/> (may also be relative), or null if not available.</param>
/// <returns>Normalized path, or null if <paramref name="path"/> can't be normalized. The resulting path doesn't need to exist.</returns>
public abstract string? NormalizePath(string path, string baseFilePath);
public abstract string? NormalizePath(string path, string? baseFilePath);
/// <summary>
/// Resolves specified path with respect to base file path.
......@@ -35,7 +35,7 @@ protected SourceReferenceResolver()
/// <param name="path">The path to resolve. May be absolute or relative.</param>
/// <param name="baseFilePath">Path of the source file that contains the <paramref name="path"/> (may also be relative), or null if not available.</param>
/// <returns>Normalized path, or null if the file can't be resolved.</returns>
public abstract string? ResolveReference(string path, string baseFilePath);
public abstract string? ResolveReference(string path, string? baseFilePath);
/// <summary>
/// Opens a <see cref="Stream"/> that allows reading the content of the specified file.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Globalization;
......@@ -83,7 +85,7 @@ public static bool TryParse(string str, out SubsystemVersion version)
if (!string.IsNullOrWhiteSpace(str))
{
string major;
string minor;
string? minor;
int index = str.IndexOf('.');
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -102,7 +102,7 @@ public override string GetMessage(IFormatProvider? formatProvider = null)
return this.Info.GetMessage(formatProvider);
}
internal override IReadOnlyList<object> Arguments
internal override IReadOnlyList<object?> Arguments
{
get { return this.Info.Arguments; }
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace Roslyn.Utilities
{
internal static class RoslynLazyInitializer
{
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T)"/>
public static T EnsureInitialized<T>([NotNull] ref T? target) where T : class
=> LazyInitializer.EnsureInitialized<T>(ref target!);
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, Func{T})"/>
public static T EnsureInitialized<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class
=> LazyInitializer.EnsureInitialized<T>(ref target!, valueFactory);
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, ref bool, ref object)"/>
public static T EnsureInitialized<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock)
=> LazyInitializer.EnsureInitialized<T>(ref target!, ref initialized, ref syncLock);
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, ref bool, ref object, Func{T})"/>
public static T EnsureInitialized<T>([AllowNull] ref T target, ref bool initialized, [NotNull] ref object? syncLock, Func<T> valueFactory)
=> LazyInitializer.EnsureInitialized<T>(ref target!, ref initialized, ref syncLock, valueFactory);
}
}
\ No newline at end of file
......@@ -94,13 +94,13 @@ public SourceFileResolver(ImmutableArray<string> searchPaths, string? baseDirect
public ImmutableArray<KeyValuePair<string, string>> PathMap => _pathMap;
public override string? NormalizePath(string path, string baseFilePath)
public override string? NormalizePath(string path, string? baseFilePath)
{
string normalizedPath = FileUtilities.NormalizeRelativePath(path, baseFilePath, _baseDirectory);
return (normalizedPath == null || _pathMap.IsDefaultOrEmpty) ? normalizedPath : PathUtilities.NormalizePathPrefix(normalizedPath, _pathMap);
}
public override string? ResolveReference(string path, string baseFilePath)
public override string? ResolveReference(string path, string? baseFilePath)
{
string resolvedPath = FileUtilities.ResolveRelativePath(path, baseFilePath, _baseDirectory, _searchPaths, FileExists);
if (resolvedPath == null)
......
......@@ -54,7 +54,7 @@ public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContex
return;
var (document, _, cancellationToken) = context;
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var member = semanticModel.GetDeclaredSymbol(container, cancellationToken);
Contract.ThrowIfNull(member);
......
......@@ -146,7 +146,8 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
return;
var model = await document.RequireSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var switchStatement = (TSwitchOperation)model.GetOperation(switchNode, cancellationToken);
// https://github.com/dotnet/roslyn/issues/40505
var switchStatement = (TSwitchOperation)model.GetOperation(switchNode, cancellationToken)!;
FixOneDiagnostic(
document, editor, model, addCases, addDefaultCase, onlyOneDiagnostic,
......
......@@ -57,7 +57,7 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
/// Analyzes the containing <c>GetHashCode</c> method to determine which fields and
/// properties were combined to form a hash code for this type.
/// </summary>
public (bool accessesBase, ImmutableArray<ISymbol> members) GetHashedMembers(ISymbol owningSymbol, IOperation operation)
public (bool accessesBase, ImmutableArray<ISymbol> members) GetHashedMembers(ISymbol owningSymbol, IOperation? operation)
{
if (!(operation is IBlockOperation blockOperation))
{
......
......@@ -278,7 +278,7 @@ public bool TryGetSemanticModel([NotNullWhen(returnValue: true)] out SemanticMod
return semanticModel;
}
var syntaxTree = await this.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var syntaxTree = await this.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var compilation = (await this.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false))!;
var result = compilation.GetSemanticModel(syntaxTree);
......
......@@ -633,7 +633,7 @@ public CompilationInfo(Compilation compilation, bool hasSuccessfullyLoaded)
await solution.GetCompilationAsync(projectReference.ProjectId, cancellationToken).ConfigureAwait(false);
compilation = compilation.WithScriptCompilationInfo(
compilation.ScriptCompilationInfo.WithPreviousScriptCompilation(previousSubmissionCompilation));
compilation.ScriptCompilationInfo.WithPreviousScriptCompilation(previousSubmissionCompilation!));
}
else
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册