C#: When creating conditionally accessed expressions, use the typeinfo from the conditional expression to ensure correct flow state and type nullability.

This commit is contained in:
Calum Grant
2019-12-20 16:09:47 +00:00
committed by Calum Grant
parent 85c9459b35
commit bcd8dca780
2 changed files with 4 additions and 3 deletions

View File

@@ -292,7 +292,7 @@ namespace Semmle.Extraction.CSharp.Entities
protected Expression(ExpressionNodeInfo info)
: base(info)
{
Syntax = (SyntaxNode)info.Node;
Syntax = (SyntaxNode)info.Node;
}
/// <summary>
@@ -374,7 +374,8 @@ namespace Semmle.Extraction.CSharp.Entities
public bool IsCompilerGenerated { get; }
public string ExprValue { get; }
public ExpressionInfo(Context cx, AnnotatedType type, Extraction.Entities.Location location, ExprKind kind, IExpressionParentEntity parent, int child, bool isCompilerGenerated, string value)
public ExpressionInfo(Context cx, AnnotatedType type, Extraction.Entities.Location location, ExprKind kind,
IExpressionParentEntity parent, int child, bool isCompilerGenerated, string value)
{
Context = cx;
Type = type;

View File

@@ -30,7 +30,7 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
public static Expression Create(ExpressionNodeInfo info, ConditionalAccessExpressionSyntax node) =>
// The qualifier is located by walking the syntax tree.
// `node.WhenNotNull` will contain a MemberBindingExpressionSyntax, calling the method below.
Create(info.Context, node.WhenNotNull, info.Parent, info.Child);
CreateFromNode(new ExpressionNodeInfo(info.Context, node.WhenNotNull, info.Parent, info.Child, info.TypeInfo));
public static Expression Create(ExpressionNodeInfo info, MemberBindingExpressionSyntax node)
{