diff --git a/src/Compilers/Core/Portable/Compilation/Extensions.cs b/src/Compilers/Core/Portable/Compilation/Extensions.cs index 51640885479bb..251ab90f46ac5 100644 --- a/src/Compilers/Core/Portable/Compilation/Extensions.cs +++ b/src/Compilers/Core/Portable/Compilation/Extensions.cs @@ -12,6 +12,17 @@ namespace Microsoft.CodeAnalysis { public static class ModelExtensions { + /// + /// Gets a semantic model based on this semantic model that can return information about calculated + /// nullability. This model is used to query for information about expressions that can have + /// inferred nullability, such as references, inferred type parameters, declared nullability + /// of var variables or discard expression, or lambda parameters. + /// + public static SemanticModel GetNullabilityAwareSemanticModel(this SemanticModel semanticModel, CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + /// /// Gets symbol information about a syntax node. /// @@ -24,12 +35,6 @@ public static class ModelExtensions return semanticModel.GetSymbolInfo(node, cancellationToken); } - // If there is no single symbol, return will be the same as GetSymbolInfoWithNullability - public static SymbolInfo GetSymbolInfoWithNullability(this SemanticModel semanticModel, SyntaxNode, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - /// /// Binds the node in the context of the specified location and get semantic information /// such as type, symbols and diagnostics. This method is used to get semantic information @@ -66,11 +71,6 @@ public static SymbolInfo GetSpeculativeSymbolInfo(this SemanticModel semanticMod return semanticModel.GetTypeInfo(node, cancellationToken); } - public static TypeInfo GetTypeInfoWithNullability(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken = default) - { - throw new NotImplementedException(); - } - /// /// If "nameSyntax" resolves to an alias name, return the IAliasSymbol corresponding /// to A. Otherwise return null. @@ -146,46 +146,6 @@ public static TypeInfo GetSpeculativeTypeInfo(this SemanticModel semanticModel, return semanticModel.GetDeclaredSymbolForNode(declaration, cancellationToken); } - public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IDiscardSymbol discard, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IEventSymbol eventSymbol, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IFieldSymbol field, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, ILocalSymbol local, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetReturnTypeWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static ImmutableArray GetTypeParametersWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetReceiverTypeWithNullability(this SemanticModel semanticModel, IMethodSymbol method, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - - public static TypeInfo GetTypeWithNullability(this SemanticModel semanticModel, IParameterSymbol local, CancellationToken ct = default) - { - throw new NotImplementedException(); - } - /// /// Gets a list of method or indexed property symbols for a syntax node. /// diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 96bf7f861ceb1..d6b5fa712e20b 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -16,14 +16,15 @@ Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation.Local.get -> Microsoft.CodeAnalysis.ILocalSymbol Microsoft.CodeAnalysis.IArrayTypeSymbol.ElementNullability.get -> Microsoft.CodeAnalysis.Nullability Microsoft.CodeAnalysis.IDiscardSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability -Microsoft.CodeAnalysis.IEventSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability -Microsoft.CodeAnalysis.IFieldSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability -Microsoft.CodeAnalysis.ILocalSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability +Microsoft.CodeAnalysis.IEventSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability +Microsoft.CodeAnalysis.IFieldSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability +Microsoft.CodeAnalysis.ILocalSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability +Microsoft.CodeAnalysis.IMethodSymbol.ReceiverNullability.get -> Microsoft.CodeAnalysis.Nullability Microsoft.CodeAnalysis.IMethodSymbol.ReturnNullability.get -> Microsoft.CodeAnalysis.Nullability -Microsoft.CodeAnalysis.IMethodSymbol.TypeArgumentsNullability.get -> System.Collections.Immutable.ImmutableArray +Microsoft.CodeAnalysis.IMethodSymbol.TypeArgumentsNullabilities.get -> System.Collections.Immutable.ImmutableArray Microsoft.CodeAnalysis.INamedTypeSymbol.TypeArgumentsNullability.get -> System.Collections.Immutable.ImmutableArray Microsoft.CodeAnalysis.IOperation.SemanticModel.get -> Microsoft.CodeAnalysis.SemanticModel -Microsoft.CodeAnalysis.IParameterSymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability +Microsoft.CodeAnalysis.IParameterSymbol.Nullability.get -> Microsoft.CodeAnalysis.Nullability Microsoft.CodeAnalysis.IPropertySymbol.DeclaredNullability.get -> Microsoft.CodeAnalysis.Nullability Microsoft.CodeAnalysis.ISymbol.ToDisplayParts(Microsoft.CodeAnalysis.Nullability nullability, Microsoft.CodeAnalysis.SymbolDisplayFormat format = null) -> System.Collections.Immutable.ImmutableArray Microsoft.CodeAnalysis.ISymbol.ToDisplayString(Microsoft.CodeAnalysis.Nullability nullability, Microsoft.CodeAnalysis.SymbolDisplayFormat format = null) -> string @@ -156,13 +157,7 @@ static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.Cod static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.Operations.IParameterInitializerOperation initializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.Operations.IPropertyInitializerOperation initializer, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph static Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph.Create(Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SemanticModel semanticModel, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.FlowAnalysis.ControlFlowGraph -static Microsoft.CodeAnalysis.ModelExtensions.GetReturnTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IMethodSymbol method, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetSymbolInfoWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.SyntaxNode , System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SymbolInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetTypeInfoWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.SyntaxNode node, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IEventSymbol eventSymbol, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IFieldSymbol field, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.ILocalSymbol local, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo -static Microsoft.CodeAnalysis.ModelExtensions.GetTypeWithNullability(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.IParameterSymbol local, System.Threading.CancellationToken ct = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.TypeInfo +static Microsoft.CodeAnalysis.ModelExtensions.GetNullabilityAwareSemanticModel(this Microsoft.CodeAnalysis.SemanticModel semanticModel, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.SemanticModel virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitCaughtException(Microsoft.CodeAnalysis.FlowAnalysis.ICaughtExceptionOperation operation) -> void virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitFlowCapture(Microsoft.CodeAnalysis.FlowAnalysis.IFlowCaptureOperation operation) -> void virtual Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitFlowCaptureReference(Microsoft.CodeAnalysis.FlowAnalysis.IFlowCaptureReferenceOperation operation) -> void diff --git a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayPartKind.cs b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayPartKind.cs index 0d2ae22b13dbd..535cc87119927 100644 --- a/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayPartKind.cs +++ b/src/Compilers/Core/Portable/SymbolDisplay/SymbolDisplayPartKind.cs @@ -66,9 +66,7 @@ public enum SymbolDisplayPartKind /// The name of a type parameter. TypeParameterName = 26, /// The name of a query range variable.. - RangeVariableName = 27, - /// The nullability of the symbol. - Nullability = 28 + RangeVariableName = 27 } internal static class InternalSymbolDisplayPartKind diff --git a/src/Compilers/Core/Portable/Symbols/IDiscardSymbol.cs b/src/Compilers/Core/Portable/Symbols/IDiscardSymbol.cs index 4063c1bafd72c..1270d364ad7bb 100644 --- a/src/Compilers/Core/Portable/Symbols/IDiscardSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IDiscardSymbol.cs @@ -14,5 +14,10 @@ public interface IDiscardSymbol : ISymbol /// The type of the discarded value. /// ITypeSymbol Type { get; } + + /// + /// The nullability of the discard symbol. + /// + Nullability Nullability { get; } } } diff --git a/src/Compilers/Core/Portable/Symbols/IEventSymbol.cs b/src/Compilers/Core/Portable/Symbols/IEventSymbol.cs index 90209caf9704f..bce890fbfe389 100644 --- a/src/Compilers/Core/Portable/Symbols/IEventSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IEventSymbol.cs @@ -19,6 +19,11 @@ public interface IEventSymbol : ISymbol /// ITypeSymbol Type { get; } + /// + /// The nullability of the event + /// + Nullability Nullability { get; } + /// /// Returns true if the event is a WinRT type event. /// diff --git a/src/Compilers/Core/Portable/Symbols/IFieldSymbol.cs b/src/Compilers/Core/Portable/Symbols/IFieldSymbol.cs index 2d4d2cc66283e..fdca49b469978 100644 --- a/src/Compilers/Core/Portable/Symbols/IFieldSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IFieldSymbol.cs @@ -44,6 +44,11 @@ public interface IFieldSymbol : ISymbol /// ITypeSymbol Type { get; } + /// + /// The declared nullability of this field + /// + Nullability Nullability { get; } + /// /// Returns false if the field wasn't declared as "const", or constant value was omitted or erroneous. /// True otherwise. diff --git a/src/Compilers/Core/Portable/Symbols/ILocalSymbol.cs b/src/Compilers/Core/Portable/Symbols/ILocalSymbol.cs index 1c70f2c1ed725..c99245d3bcc34 100644 --- a/src/Compilers/Core/Portable/Symbols/ILocalSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/ILocalSymbol.cs @@ -16,6 +16,11 @@ public interface ILocalSymbol : ISymbol /// ITypeSymbol Type { get; } + /// + /// The declared nullability of this local + /// + Nullability Nullability { get; } + /// /// Returns true if this local variable was declared as "const" (i.e. is a constant declaration). /// Also returns true for an enum member. diff --git a/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs b/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs index 85043194a20cb..2effc607028f6 100644 --- a/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs @@ -90,6 +90,11 @@ public interface IMethodSymbol : ISymbol /// ITypeSymbol ReturnType { get; } + /// + /// The nullability of the return of the method. + /// + Nullability ReturnNullability { get; } + /// /// Returns the type arguments that have been substituted for the type parameters. /// If nothing has been substituted for a given type parameter, @@ -97,6 +102,12 @@ public interface IMethodSymbol : ISymbol /// ImmutableArray TypeArguments { get; } + /// + /// Returns the nullablities of the type arguments that have been subsituted for the + /// type parameters. + /// + ImmutableArray TypeArgumentsNullabilities { get; } + /// /// Get the type parameters on this method. If the method has not generic, /// returns an empty list. @@ -135,6 +146,12 @@ public interface IMethodSymbol : ISymbol /// ITypeSymbol ReceiverType { get; } + /// + /// If this method can be applied to an object, returns the nullability of the object it is + /// applied to. + /// + Nullability ReceiverNullability { get; } + /// /// If this method is a reduced extension method, returns the definition of extension /// method from which this was reduced. Otherwise, returns null. diff --git a/src/Compilers/Core/Portable/Symbols/IParameterSymbol.cs b/src/Compilers/Core/Portable/Symbols/IParameterSymbol.cs index 10b2937f2187b..5ed0a694fa0f7 100644 --- a/src/Compilers/Core/Portable/Symbols/IParameterSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IParameterSymbol.cs @@ -40,6 +40,11 @@ public interface IParameterSymbol : ISymbol /// ITypeSymbol Type { get; } + /// + /// Gets the nullability of the parameter. + /// + Nullability Nullability { get; } + /// /// Custom modifiers associated with the parameter type, or an empty array if there are none. ///