未验证 提交 85967eb1 编写于 作者: F Fred Silberberg 提交者: GitHub

Merge pull request #45712 from alrz/output-type

......@@ -1948,7 +1948,8 @@ private IConstantPatternOperation CreateBoundConstantPatternOperation(BoundConst
SyntaxNode syntax = boundConstantPattern.Syntax;
bool isImplicit = boundConstantPattern.WasCompilerGenerated;
TypeSymbol inputType = boundConstantPattern.InputType;
return new CSharpLazyConstantPatternOperation(inputType.GetPublicSymbol(), this, value, _semanticModel, syntax, isImplicit);
TypeSymbol narrowedType = boundConstantPattern.ConvertedType;
return new CSharpLazyConstantPatternOperation(inputType.GetPublicSymbol(), narrowedType.GetPublicSymbol(), this, value, _semanticModel, syntax, isImplicit);
}
private IOperation CreateBoundRelationalPatternOperation(BoundRelationalPattern boundRelationalPattern)
......@@ -1958,7 +1959,8 @@ private IOperation CreateBoundRelationalPatternOperation(BoundRelationalPattern
SyntaxNode syntax = boundRelationalPattern.Syntax;
bool isImplicit = boundRelationalPattern.WasCompilerGenerated;
TypeSymbol inputType = boundRelationalPattern.InputType;
return new CSharpLazyRelationalPatternOperation(inputType.GetPublicSymbol(), this, operatorKind, value, _semanticModel, syntax, isImplicit);
TypeSymbol narrowedType = boundRelationalPattern.ConvertedType;
return new CSharpLazyRelationalPatternOperation(inputType.GetPublicSymbol(), narrowedType.GetPublicSymbol(), this, operatorKind, value, _semanticModel, syntax, isImplicit);
}
private IDeclarationPatternOperation CreateBoundDeclarationPatternOperation(BoundDeclarationPattern boundDeclarationPattern)
......@@ -1970,11 +1972,12 @@ private IDeclarationPatternOperation CreateBoundDeclarationPatternOperation(Boun
}
ITypeSymbol inputType = boundDeclarationPattern.InputType.GetPublicSymbol();
ITypeSymbol narrowedType = boundDeclarationPattern.ConvertedType.GetPublicSymbol();
bool acceptsNull = boundDeclarationPattern.IsVar;
ITypeSymbol matchedType = acceptsNull ? null : boundDeclarationPattern.DeclaredType.GetPublicTypeSymbol();
SyntaxNode syntax = boundDeclarationPattern.Syntax;
bool isImplicit = boundDeclarationPattern.WasCompilerGenerated;
return new DeclarationPatternOperation(inputType, matchedType, variable, acceptsNull, _semanticModel, syntax, isImplicit);
return new DeclarationPatternOperation(inputType, narrowedType, matchedType, variable, acceptsNull, _semanticModel, syntax, isImplicit);
}
private IRecursivePatternOperation CreateBoundRecursivePatternOperation(BoundRecursivePattern boundRecursivePattern)
......@@ -1992,6 +1995,7 @@ private IOperation CreateBoundTypePatternOperation(BoundTypePattern boundTypePat
return new TypePatternOperation(
matchedType: boundTypePattern.ConvertedType.GetPublicSymbol(),
inputType: boundTypePattern.InputType.GetPublicSymbol(),
narrowedType: boundTypePattern.ConvertedType.GetPublicSymbol(),
semanticModel: _semanticModel,
syntax: boundTypePattern.Syntax,
type: null, // this is not an expression
......@@ -2137,7 +2141,8 @@ private IOperation CreateRangeExpressionOperation(BoundRangeExpression boundRang
private IOperation CreateBoundDiscardPatternOperation(BoundDiscardPattern boundNode)
{
return new DiscardPatternOperation(
boundNode.InputType.GetPublicSymbol(),
inputType: boundNode.InputType.GetPublicSymbol(),
narrowedType: boundNode.ConvertedType.GetPublicSymbol(),
_semanticModel,
boundNode.Syntax,
isImplicit: boundNode.WasCompilerGenerated);
......
......@@ -42,6 +42,8 @@ internal sealed class CSharpLazyNonePatternOperation : LazyNoneOperation, IPatte
public ITypeSymbol InputType => _boundNode.InputType.GetITypeSymbol(NullableAnnotation.None);
public ITypeSymbol NarrowedType => _boundNode.ConvertedType.GetITypeSymbol(NullableAnnotation.None);
protected override ImmutableArray<IOperation> GetChildren() => _operationFactory.GetIOperationChildren(_boundNode);
}
......@@ -1536,8 +1538,8 @@ internal sealed class CSharpLazyConstantPatternOperation : LazyConstantPatternOp
private readonly CSharpOperationFactory _operationFactory;
private readonly BoundNode _value;
internal CSharpLazyConstantPatternOperation(ITypeSymbol inputType, CSharpOperationFactory operationFactory, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
base(inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
internal CSharpLazyConstantPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, CSharpOperationFactory operationFactory, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
base(inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{
_operationFactory = operationFactory;
_value = value;
......@@ -1554,8 +1556,8 @@ internal sealed class CSharpLazyRelationalPatternOperation : LazyRelationalPatte
private readonly CSharpOperationFactory _operationFactory;
private readonly BoundNode _value;
internal CSharpLazyRelationalPatternOperation(ITypeSymbol inputType, CSharpOperationFactory operationFactory, BinaryOperatorKind operatorKind, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
base(operatorKind, inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
internal CSharpLazyRelationalPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, CSharpOperationFactory operationFactory, BinaryOperatorKind operatorKind, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
base(operatorKind, inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{
_operationFactory = operationFactory;
_value = value;
......@@ -1580,6 +1582,7 @@ internal sealed partial class CSharpLazyNegatedPatternOperation : LazyNegatedPat
BoundNegatedPattern boundNegatedPattern,
SemanticModel semanticModel)
: base(inputType: boundNegatedPattern.InputType.GetPublicSymbol(),
narrowedType: boundNegatedPattern.ConvertedType.GetPublicSymbol(),
semanticModel: semanticModel,
syntax: boundNegatedPattern.Syntax,
type: null,
......@@ -1608,6 +1611,7 @@ internal sealed partial class CSharpLazyBinaryPatternOperation : LazyBinaryPatte
SemanticModel semanticModel)
: base(operatorKind: boundBinaryPattern.Disjunction ? BinaryOperatorKind.Or : BinaryOperatorKind.And,
inputType: boundBinaryPattern.InputType.GetPublicSymbol(),
narrowedType: boundBinaryPattern.ConvertedType.GetPublicSymbol(),
semanticModel: semanticModel,
syntax: boundBinaryPattern.Syntax,
type: null,
......@@ -1640,6 +1644,7 @@ internal sealed partial class CSharpLazyRecursivePatternOperation : LazyRecursiv
BoundRecursivePattern boundRecursivePattern,
SemanticModel semanticModel)
: base(inputType: boundRecursivePattern.InputType.GetPublicSymbol(),
narrowedType: boundRecursivePattern.ConvertedType.GetPublicSymbol(),
matchedType: (boundRecursivePattern.DeclaredType?.Type ?? boundRecursivePattern.InputType.StrippedType()).GetPublicSymbol(),
deconstructSymbol: boundRecursivePattern.DeconstructMethod.GetPublicSymbol(),
declaredSymbol: boundRecursivePattern.Variable.GetPublicSymbol(),
......@@ -1704,6 +1709,7 @@ internal sealed partial class CSharpLazyITuplePatternOperation : LazyRecursivePa
public CSharpLazyITuplePatternOperation(CSharpOperationFactory operationFactory, BoundITuplePattern boundITuplePattern, SemanticModel semanticModel)
: base(inputType: boundITuplePattern.InputType.GetPublicSymbol(),
narrowedType: boundITuplePattern.ConvertedType.GetPublicSymbol(),
matchedType: boundITuplePattern.InputType.StrippedType().GetPublicSymbol(),
deconstructSymbol: boundITuplePattern.GetLengthMethod.ContainingType.GetPublicSymbol(),
declaredSymbol: null,
......
......@@ -389,7 +389,7 @@ static void M(object o)
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null) (Syntax: '_') (InputType: System.Object)
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null) (Syntax: '_') (InputType: System.Object, NarrowedType: System.Object)
Next (Regular) Block[B2]
Block[B2] - Exit
Predecessors: [B1*2]
......
......@@ -1444,7 +1444,7 @@ void M(object o)
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int x') (InputType: System.Object, DeclaredSymbol: System.Int32 x, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int x') (InputType: System.Object, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 x, MatchesNull: False)
Collection:
ILocalReferenceOperation: arr (OperationKind.LocalReference, Type: System.Int32[]) (Syntax: 'arr')
Body:
......
......@@ -703,7 +703,7 @@ private static void A(bool flag, int number)
Value:
ILocalReferenceOperation: o (OperationKind.LocalReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int i') (InputType: System.Object, DeclaredSymbol: System.Int32 i, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int i') (InputType: System.Object, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 i, MatchesNull: False)
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: number) (OperationKind.Argument, Type: null) (Syntax: '1')
......@@ -745,7 +745,7 @@ private void M()
Value:
ILocalReferenceOperation: obj (OperationKind.LocalReference, Type: System.Object) (Syntax: 'obj')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string str') (InputType: System.Object, DeclaredSymbol: System.String str, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string str') (InputType: System.Object, NarrowedType: System.String, DeclaredSymbol: System.String str, MatchesNull: False)
WhenTrue:
IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'Console.WriteLine(str);')
......@@ -856,7 +856,7 @@ private static void A(bool flag, int number)
Value:
ILocalReferenceOperation: o (OperationKind.LocalReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int i') (InputType: System.Object, DeclaredSymbol: System.Int32 i, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int i') (InputType: System.Object, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 i, MatchesNull: False)
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: number) (OperationKind.Argument, Type: null) (Syntax: '1')
......@@ -1252,7 +1252,7 @@ private void M()
Value:
ILocalReferenceOperation: obj (OperationKind.LocalReference, Type: System.Object) (Syntax: 'obj')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string str') (InputType: System.Object, DeclaredSymbol: System.String str, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string str') (InputType: System.Object, NarrowedType: System.String, DeclaredSymbol: System.String str, MatchesNull: False)
WhenTrue:
IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'Console.WriteLine(str);')
......
......@@ -853,7 +853,7 @@ public void M(int x)
Clauses:
IPatternCaseClauseOperation (Label Id: 0) (CaseKind.Pattern) (OperationKind.CaseClause, Type: null) (Syntax: 'case var y ... (x >= 10):')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var y') (InputType: System.Int32, DeclaredSymbol: System.Int32 y, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var y') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 y, MatchesNull: True)
Guard:
IBinaryOperation (BinaryOperatorKind.GreaterThanOrEqual) (OperationKind.Binary, Type: System.Boolean) (Syntax: 'x >= 10')
Left:
......@@ -1045,7 +1045,7 @@ public void Method1(object x)
Value:
IParameterReferenceOperation: x (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'x')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int y') (InputType: System.Object, DeclaredSymbol: System.Int32 y, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'int y') (InputType: System.Object, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 y, MatchesNull: False)
";
var expectedDiagnostics = DiagnosticDescription.None;
......
......@@ -1302,7 +1302,7 @@ void M1()
Value:
ILocalReferenceOperation: y (OperationKind.LocalReference, Type: System.Int32, IsInvalid) (Syntax: 'y')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Declarators:
IVariableDeclaratorOperation (Symbol: System.Int32[] x) (OperationKind.VariableDeclarator, Type: null) (Syntax: 'x')
Initializer:
......@@ -1359,7 +1359,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......@@ -1794,7 +1794,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......@@ -2314,7 +2314,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......@@ -2376,7 +2376,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......@@ -2435,7 +2435,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......@@ -2845,7 +2845,7 @@ void M1()
Arms(1):
ISwitchExpressionArmOperation (1 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: 'int z => 42')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'int z') (InputType: System.Int32, NarrowedType: System.Int32, DeclaredSymbol: System.Int32 z, MatchesNull: False)
Value:
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 42, IsInvalid) (Syntax: '42')
Locals: Local_1: System.Int32 z
......
......@@ -94,7 +94,7 @@ static void Main(string[] args)
Clauses:
IPatternCaseClauseOperation (Label Id: 1) (CaseKind.Pattern) (OperationKind.CaseClause, Type: null, IsInvalid) (Syntax: 'case 1:')
Pattern:
IConstantPatternOperation (OperationKind.ConstantPattern, Type: null, IsInvalid, IsImplicit) (Syntax: '1') (InputType: Program)
IConstantPatternOperation (OperationKind.ConstantPattern, Type: null, IsInvalid, IsImplicit) (Syntax: '1') (InputType: Program, NarrowedType: Program)
Value:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: Program, IsInvalid, IsImplicit) (Syntax: '1')
Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
......@@ -389,10 +389,10 @@ static void Main(string[] args)
Value:
IParameterReferenceOperation: args (OperationKind.ParameterReference, Type: System.String[], IsInvalid) (Syntax: 'args')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '(var x1, var x2)') (InputType: System.String[], DeclaredSymbol: null, MatchedType: System.String[], DeconstructSymbol: null)
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '(var x1, var x2)') (InputType: System.String[], NarrowedType: System.String[], DeclaredSymbol: null, MatchedType: System.String[], DeconstructSymbol: null)
DeconstructionSubpatterns (2):
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'var x1') (InputType: ?, DeclaredSymbol: ?? x1, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'var x2') (InputType: ?, DeclaredSymbol: ?? x2, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'var x1') (InputType: ?, NarrowedType: ?, DeclaredSymbol: ?? x1, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'var x2') (InputType: ?, NarrowedType: ?, DeclaredSymbol: ?? x2, MatchesNull: True)
PropertySubpatterns (0)
";
var expectedDiagnostics = new DiagnosticDescription[] {
......
......@@ -648,7 +648,7 @@ static void M(object o)
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string s') (InputType: System.Object, DeclaredSymbol: System.String s, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string s') (InputType: System.Object, NarrowedType: System.String, DeclaredSymbol: System.String s, MatchesNull: False)
Handler:
IBlockOperation (0 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
Finally:
......@@ -696,7 +696,7 @@ static void M(object o)
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string s') (InputType: System.Object, DeclaredSymbol: System.String s, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'string s') (InputType: System.Object, NarrowedType: System.String, DeclaredSymbol: System.String s, MatchesNull: False)
Handler:
IBlockOperation (0 statements) (OperationKind.Block, Type: null) (Syntax: '{ ... }')
Finally:
......
......@@ -2228,7 +2228,7 @@ .maxstack 2
Value:
ILocalReferenceOperation: ptr (OperationKind.LocalReference, Type: delegate*<System.Void>) (Syntax: 'ptr')
Pattern:
IConstantPatternOperation (OperationKind.ConstantPattern, Type: null) (Syntax: 'null') (InputType: delegate*<System.Void>)
IConstantPatternOperation (OperationKind.ConstantPattern, Type: null) (Syntax: 'null') (InputType: delegate*<System.Void>, NarrowedType: delegate*<System.Void>)
Value:
ILiteralOperation (OperationKind.Literal, Type: null, Constant: null) (Syntax: 'null')
");
......@@ -2238,7 +2238,7 @@ .maxstack 2
Value:
ILocalReferenceOperation: ptr (OperationKind.LocalReference, Type: delegate*<System.Void>) (Syntax: 'ptr')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var v') (InputType: delegate*<System.Void>, DeclaredSymbol: delegate*<System.Void> v, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var v') (InputType: delegate*<System.Void>, NarrowedType: delegate*<System.Void>, DeclaredSymbol: delegate*<System.Void> v, MatchesNull: True)
");
comp = CreateCompilationWithFunctionPointers(source, parseOptions: TestOptions.Regular7_3);
......@@ -2285,9 +2285,9 @@ static void Main()
Value:
ILocalReferenceOperation: ptr (OperationKind.LocalReference, Type: delegate*<System.Void>) (Syntax: 'ptr')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '(x)') (InputType: ?, DeclaredSymbol: null, MatchedType: ?, DeconstructSymbol: null)
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '(x)') (InputType: ?, NarrowedType: ?, DeclaredSymbol: null, MatchedType: ?, DeconstructSymbol: null)
DeconstructionSubpatterns (1):
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'x') (InputType: ?, DeclaredSymbol: ?? x, MatchesNull: True)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'x') (InputType: ?, NarrowedType: ?, DeclaredSymbol: ?? x, MatchesNull: True)
PropertySubpatterns (0)
");
}
......@@ -2327,7 +2327,7 @@ void M(delegate*<void> ptr)
Value:
IParameterReferenceOperation: ptr (OperationKind.ParameterReference, Type: delegate*<System.Void>) (Syntax: 'ptr')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '{ } _') (InputType: ?, DeclaredSymbol: null, MatchedType: ?, DeconstructSymbol: null)
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '{ } _') (InputType: ?, NarrowedType: ?, DeclaredSymbol: null, MatchedType: ?, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (0)
");
......@@ -2433,7 +2433,7 @@ void M(C c)
Value:
IParameterReferenceOperation: c (OperationKind.ParameterReference, Type: C) (Syntax: 'c')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '{ O: delegate*<void> _ }') (InputType: C, DeclaredSymbol: null, MatchedType: C, DeconstructSymbol: null)
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: '{ O: delegate*<void> _ }') (InputType: C, NarrowedType: C, DeclaredSymbol: null, MatchedType: C, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'O: delegate*<void> _')
......@@ -2442,7 +2442,7 @@ void M(C c)
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: PatternInput) (OperationKind.InstanceReference, Type: C, IsImplicit) (Syntax: 'O')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'delegate*<void> _') (InputType: System.Object, DeclaredSymbol: null, MatchesNull: False)
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null, IsInvalid) (Syntax: 'delegate*<void> _') (InputType: System.Object, NarrowedType: delegate*<System.Void>, DeclaredSymbol: null, MatchesNull: False)
");
}
......
......@@ -1435,7 +1435,7 @@ public static class C {
Value:
IFlowCaptureReferenceOperation: 1 (OperationKind.FlowCaptureReference, Type: System.Object, IsInvalid, IsImplicit) (Syntax: 'o')
Pattern:
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object)
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object, NarrowedType: System.Object)
Leaving: {R2}
Next (Regular) Block[B2]
Block[B2] - Block
......@@ -1492,7 +1492,7 @@ public static class C {
Value:
IFlowCaptureReferenceOperation: 3 (OperationKind.FlowCaptureReference, Type: System.Object, IsInvalid, IsImplicit) (Syntax: 'o')
Pattern:
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object)
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object, NarrowedType: System.Object)
Leaving: {R4}
Next (Regular) Block[B6]
Block[B6] - Block
......@@ -1560,7 +1560,7 @@ public static class C {
Arms(1):
ISwitchExpressionArmOperation (0 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: '_ => default')
Pattern:
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object)
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object, NarrowedType: System.Object)
Value:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: C?, Constant: null, IsInvalid, IsImplicit) (Syntax: 'default')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
......@@ -1580,7 +1580,7 @@ public static class C {
Arms(1):
ISwitchExpressionArmOperation (0 locals) (OperationKind.SwitchExpressionArm, Type: null, IsInvalid) (Syntax: '_ => throw null!')
Pattern:
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object)
IDiscardPatternOperation (OperationKind.DiscardPattern, Type: null, IsInvalid) (Syntax: '_') (InputType: System.Object, NarrowedType: System.Object)
Value:
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: C, IsInvalid, IsImplicit) (Syntax: 'throw null!')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
......
......@@ -2308,6 +2308,10 @@ public interface IPatternOperation : IOperation
/// The input type to the pattern-matching operation.
/// </summary>
ITypeSymbol InputType { get; }
/// <summary>
/// The narrowed type of the pattern-matching operation.
/// </summary>
ITypeSymbol NarrowedType { get; }
}
/// <summary>
/// Represents a pattern with a constant value.
......@@ -7166,17 +7170,19 @@ public override IOperation FormatString
}
internal abstract partial class BasePatternOperation : Operation, IPatternOperation
{
protected BasePatternOperation(ITypeSymbol inputType, OperationKind kind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
protected BasePatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, OperationKind kind, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(kind, semanticModel, syntax, type, constantValue, isImplicit)
{
InputType = inputType;
NarrowedType = narrowedType;
}
public ITypeSymbol InputType { get; }
public ITypeSymbol NarrowedType { get; }
}
internal abstract partial class BaseConstantPatternOperation : BasePatternOperation, IConstantPatternOperation
{
internal BaseConstantPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.ConstantPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
internal BaseConstantPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.ConstantPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
public abstract IOperation Value { get; }
public override IEnumerable<IOperation> Children
{
......@@ -7190,8 +7196,8 @@ public override IEnumerable<IOperation> Children
}
internal sealed partial class ConstantPatternOperation : BaseConstantPatternOperation, IConstantPatternOperation
{
internal ConstantPatternOperation(IOperation value, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, semanticModel, syntax, type, constantValue, isImplicit)
internal ConstantPatternOperation(IOperation value, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit)
{
Value = SetParentOperation(value, this);
}
......@@ -7200,8 +7206,8 @@ internal ConstantPatternOperation(IOperation value, ITypeSymbol inputType, Seman
internal abstract partial class LazyConstantPatternOperation : BaseConstantPatternOperation, IConstantPatternOperation
{
private IOperation _lazyValue = s_unset;
internal LazyConstantPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, semanticModel, syntax, type, constantValue, isImplicit){ }
internal LazyConstantPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit){ }
protected abstract IOperation CreateValue();
public override IOperation Value
{
......@@ -7219,8 +7225,8 @@ public override IOperation Value
}
internal sealed partial class DeclarationPatternOperation : BasePatternOperation, IDeclarationPatternOperation
{
internal DeclarationPatternOperation(ITypeSymbol matchedType, bool matchesNull, ISymbol declaredSymbol, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.DeclarationPattern, semanticModel, syntax, type, constantValue, isImplicit)
internal DeclarationPatternOperation(ITypeSymbol matchedType, bool matchesNull, ISymbol declaredSymbol, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.DeclarationPattern, semanticModel, syntax, type, constantValue, isImplicit)
{
MatchedType = matchedType;
MatchesNull = matchesNull;
......@@ -7745,8 +7751,8 @@ public override ImmutableArray<IOperation> DimensionSizes
}
internal abstract partial class BaseRecursivePatternOperation : BasePatternOperation, IRecursivePatternOperation
{
internal BaseRecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ISymbol declaredSymbol, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.RecursivePattern, semanticModel, syntax, type, constantValue, isImplicit)
internal BaseRecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ISymbol declaredSymbol, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.RecursivePattern, semanticModel, syntax, type, constantValue, isImplicit)
{
MatchedType = matchedType;
DeconstructSymbol = deconstructSymbol;
......@@ -7776,8 +7782,8 @@ public override IEnumerable<IOperation> Children
}
internal sealed partial class RecursivePatternOperation : BaseRecursivePatternOperation, IRecursivePatternOperation
{
internal RecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ImmutableArray<IPatternOperation> deconstructionSubpatterns, ImmutableArray<IPropertySubpatternOperation> propertySubpatterns, ISymbol declaredSymbol, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(matchedType, deconstructSymbol, declaredSymbol, inputType, semanticModel, syntax, type, constantValue, isImplicit)
internal RecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ImmutableArray<IPatternOperation> deconstructionSubpatterns, ImmutableArray<IPropertySubpatternOperation> propertySubpatterns, ISymbol declaredSymbol, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(matchedType, deconstructSymbol, declaredSymbol, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit)
{
DeconstructionSubpatterns = SetParentOperation(deconstructionSubpatterns, this);
PropertySubpatterns = SetParentOperation(propertySubpatterns, this);
......@@ -7789,8 +7795,8 @@ internal abstract partial class LazyRecursivePatternOperation : BaseRecursivePat
{
private ImmutableArray<IPatternOperation> _lazyDeconstructionSubpatterns;
private ImmutableArray<IPropertySubpatternOperation> _lazyPropertySubpatterns;
internal LazyRecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ISymbol declaredSymbol, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(matchedType, deconstructSymbol, declaredSymbol, inputType, semanticModel, syntax, type, constantValue, isImplicit){ }
internal LazyRecursivePatternOperation(ITypeSymbol matchedType, ISymbol deconstructSymbol, ISymbol declaredSymbol, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(matchedType, deconstructSymbol, declaredSymbol, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit){ }
protected abstract ImmutableArray<IPatternOperation> CreateDeconstructionSubpatterns();
public override ImmutableArray<IPatternOperation> DeconstructionSubpatterns
{
......@@ -7822,8 +7828,8 @@ public override ImmutableArray<IPropertySubpatternOperation> PropertySubpatterns
}
internal sealed partial class DiscardPatternOperation : BasePatternOperation, IDiscardPatternOperation
{
internal DiscardPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.DiscardPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
internal DiscardPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.DiscardPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
public override IEnumerable<IOperation> Children => Array.Empty<IOperation>();
public override void Accept(OperationVisitor visitor) => visitor.VisitDiscardPattern(this);
public override TResult Accept<TArgument, TResult>(OperationVisitor<TArgument, TResult> visitor, TArgument argument) => visitor.VisitDiscardPattern(this, argument);
......@@ -8386,8 +8392,8 @@ public override IVariableDeclarationGroupOperation DeclarationGroup
}
internal abstract partial class BaseNegatedPatternOperation : BasePatternOperation, INegatedPatternOperation
{
internal BaseNegatedPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.NegatedPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
internal BaseNegatedPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.NegatedPattern, semanticModel, syntax, type, constantValue, isImplicit) { }
public abstract IPatternOperation Pattern { get; }
public override IEnumerable<IOperation> Children
{
......@@ -8401,8 +8407,8 @@ public override IEnumerable<IOperation> Children
}
internal sealed partial class NegatedPatternOperation : BaseNegatedPatternOperation, INegatedPatternOperation
{
internal NegatedPatternOperation(IPatternOperation pattern, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, semanticModel, syntax, type, constantValue, isImplicit)
internal NegatedPatternOperation(IPatternOperation pattern, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit)
{
Pattern = SetParentOperation(pattern, this);
}
......@@ -8411,8 +8417,8 @@ internal NegatedPatternOperation(IPatternOperation pattern, ITypeSymbol inputTyp
internal abstract partial class LazyNegatedPatternOperation : BaseNegatedPatternOperation, INegatedPatternOperation
{
private IPatternOperation _lazyPattern = s_unsetPattern;
internal LazyNegatedPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, semanticModel, syntax, type, constantValue, isImplicit){ }
internal LazyNegatedPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit){ }
protected abstract IPatternOperation CreatePattern();
public override IPatternOperation Pattern
{
......@@ -8430,8 +8436,8 @@ public override IPatternOperation Pattern
}
internal abstract partial class BaseBinaryPatternOperation : BasePatternOperation, IBinaryPatternOperation
{
internal BaseBinaryPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.BinaryPattern, semanticModel, syntax, type, constantValue, isImplicit)
internal BaseBinaryPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.BinaryPattern, semanticModel, syntax, type, constantValue, isImplicit)
{
OperatorKind = operatorKind;
}
......@@ -8451,8 +8457,8 @@ public override IEnumerable<IOperation> Children
}
internal sealed partial class BinaryPatternOperation : BaseBinaryPatternOperation, IBinaryPatternOperation
{
internal BinaryPatternOperation(BinaryOperatorKind operatorKind, IPatternOperation leftPattern, IPatternOperation rightPattern, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, semanticModel, syntax, type, constantValue, isImplicit)
internal BinaryPatternOperation(BinaryOperatorKind operatorKind, IPatternOperation leftPattern, IPatternOperation rightPattern, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit)
{
LeftPattern = SetParentOperation(leftPattern, this);
RightPattern = SetParentOperation(rightPattern, this);
......@@ -8464,8 +8470,8 @@ internal abstract partial class LazyBinaryPatternOperation : BaseBinaryPatternOp
{
private IPatternOperation _lazyLeftPattern = s_unsetPattern;
private IPatternOperation _lazyRightPattern = s_unsetPattern;
internal LazyBinaryPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, semanticModel, syntax, type, constantValue, isImplicit){ }
internal LazyBinaryPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit){ }
protected abstract IPatternOperation CreateLeftPattern();
public override IPatternOperation LeftPattern
{
......@@ -8497,8 +8503,8 @@ public override IPatternOperation RightPattern
}
internal sealed partial class TypePatternOperation : BasePatternOperation, ITypePatternOperation
{
internal TypePatternOperation(ITypeSymbol matchedType, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.TypePattern, semanticModel, syntax, type, constantValue, isImplicit)
internal TypePatternOperation(ITypeSymbol matchedType, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.TypePattern, semanticModel, syntax, type, constantValue, isImplicit)
{
MatchedType = matchedType;
}
......@@ -8509,8 +8515,8 @@ internal TypePatternOperation(ITypeSymbol matchedType, ITypeSymbol inputType, Se
}
internal abstract partial class BaseRelationalPatternOperation : BasePatternOperation, IRelationalPatternOperation
{
internal BaseRelationalPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, OperationKind.RelationalPattern, semanticModel, syntax, type, constantValue, isImplicit)
internal BaseRelationalPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(inputType, narrowedType, OperationKind.RelationalPattern, semanticModel, syntax, type, constantValue, isImplicit)
{
OperatorKind = operatorKind;
}
......@@ -8528,8 +8534,8 @@ public override IEnumerable<IOperation> Children
}
internal sealed partial class RelationalPatternOperation : BaseRelationalPatternOperation, IRelationalPatternOperation
{
internal RelationalPatternOperation(BinaryOperatorKind operatorKind, IOperation value, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, semanticModel, syntax, type, constantValue, isImplicit)
internal RelationalPatternOperation(BinaryOperatorKind operatorKind, IOperation value, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit)
{
Value = SetParentOperation(value, this);
}
......@@ -8538,8 +8544,8 @@ internal RelationalPatternOperation(BinaryOperatorKind operatorKind, IOperation
internal abstract partial class LazyRelationalPatternOperation : BaseRelationalPatternOperation, IRelationalPatternOperation
{
private IOperation _lazyValue = s_unset;
internal LazyRelationalPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, semanticModel, syntax, type, constantValue, isImplicit){ }
internal LazyRelationalPatternOperation(BinaryOperatorKind operatorKind, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, ConstantValue constantValue, bool isImplicit)
: base(operatorKind, inputType, narrowedType, semanticModel, syntax, type, constantValue, isImplicit){ }
protected abstract IOperation CreateValue();
public override IOperation Value
{
......
......@@ -6542,7 +6542,7 @@ public override IOperation VisitDiscardOperation(IDiscardOperation operation, in
public override IOperation VisitDiscardPattern(IDiscardPatternOperation pat, int? captureIdForResult)
{
return new DiscardPatternOperation(pat.InputType, semanticModel: null, pat.Syntax, IsImplicit(pat));
return new DiscardPatternOperation(pat.InputType, pat.NarrowedType, semanticModel: null, pat.Syntax, IsImplicit(pat));
}
public override IOperation VisitOmittedArgument(IOmittedArgumentOperation operation, int? captureIdForResult)
......@@ -6713,7 +6713,7 @@ public override IOperation VisitTranslatedQuery(ITranslatedQueryOperation operat
public override IOperation VisitConstantPattern(IConstantPatternOperation operation, int? captureIdForResult)
{
return new ConstantPatternOperation(operation.InputType, Visit(operation.Value), semanticModel: null,
return new ConstantPatternOperation(operation.InputType, operation.NarrowedType, Visit(operation.Value), semanticModel: null,
syntax: operation.Syntax, isImplicit: IsImplicit(operation));
}
......@@ -6723,6 +6723,7 @@ public override IOperation VisitRelationalPattern(IRelationalPatternOperation op
operatorKind: operation.OperatorKind,
value: Visit(operation.Value),
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
semanticModel: null,
syntax: operation.Syntax,
type: operation.Type,
......@@ -6737,6 +6738,7 @@ public override IOperation VisitBinaryPattern(IBinaryPatternOperation operation,
leftPattern: (IPatternOperation)Visit(operation.LeftPattern),
rightPattern: (IPatternOperation)Visit(operation.RightPattern),
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
semanticModel: null,
syntax: operation.Syntax,
type: operation.Type,
......@@ -6749,6 +6751,7 @@ public override IOperation VisitNegatedPattern(INegatedPatternOperation operatio
return new NegatedPatternOperation(
pattern: (IPatternOperation)Visit(operation.Pattern),
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
semanticModel: null,
syntax: operation.Syntax,
type: operation.Type,
......@@ -6761,6 +6764,7 @@ public override IOperation VisitTypePattern(ITypePatternOperation operation, int
return new TypePatternOperation(
matchedType: operation.MatchedType,
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
semanticModel: null,
syntax: operation.Syntax,
type: operation.Type,
......@@ -6772,6 +6776,7 @@ public override IOperation VisitDeclarationPattern(IDeclarationPatternOperation
{
return new DeclarationPatternOperation(
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
matchedType: operation.MatchedType,
operation.DeclaredSymbol,
operation.MatchesNull,
......@@ -6784,6 +6789,7 @@ public override IOperation VisitRecursivePattern(IRecursivePatternOperation oper
{
return new RecursivePatternOperation(
inputType: operation.InputType,
narrowedType: operation.NarrowedType,
matchedType: operation.MatchedType,
operation.DeconstructSymbol,
operation.DeconstructionSubpatterns.SelectAsArray(p => (IPatternOperation)Visit(p)),
......
......@@ -30,7 +30,7 @@ internal abstract class Operation : IOperation
protected static readonly IObjectOrCollectionInitializerOperation s_unsetObjectOrCollectionInitializer = new ObjectOrCollectionInitializerOperation(
initializers: ImmutableArray<IOperation>.Empty, semanticModel: null, syntax: null, type: null, constantValue: null, isImplicit: true);
protected static readonly IPatternOperation s_unsetPattern = new ConstantPatternOperation(
value: null, inputType: null, semanticModel: null, syntax: null, type: null, constantValue: null, isImplicit: true);
value: null, inputType: null, narrowedType: null, semanticModel: null, syntax: null, type: null, constantValue: null, isImplicit: true);
protected static readonly IVariableDeclarationGroupOperation s_unsetVariableDeclarationGroup = new VariableDeclarationGroupOperation(
declarations: ImmutableArray<IVariableDeclarationOperation>.Empty, semanticModel: null, syntax: null, type: null, constantValue: null, isImplicit: true);
protected static readonly IVariableInitializerOperation s_unsetVariableInitializer = new VariableInitializerOperation(
......
......@@ -526,7 +526,7 @@ public override IOperation VisitIsPattern(IIsPatternOperation operation, object
public override IOperation VisitConstantPattern(IConstantPatternOperation operation, object argument)
{
return new ConstantPatternOperation(operation.InputType, Visit(operation.Value), ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.IsImplicit);
return new ConstantPatternOperation(operation.InputType, operation.NarrowedType, Visit(operation.Value), ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.IsImplicit);
}
public override IOperation VisitDeclarationPattern(IDeclarationPatternOperation operation, object argument)
......@@ -536,6 +536,7 @@ public override IOperation VisitDeclarationPattern(IDeclarationPatternOperation
operation.MatchesNull,
operation.DeclaredSymbol,
operation.InputType,
operation.NarrowedType,
((Operation)operation).OwningSemanticModel,
operation.Syntax,
operation.Type,
......@@ -547,6 +548,7 @@ public override IOperation VisitRecursivePattern(IRecursivePatternOperation oper
{
return new RecursivePatternOperation(
operation.InputType,
operation.NarrowedType,
operation.MatchedType,
operation.DeconstructSymbol,
VisitArray(operation.DeconstructionSubpatterns),
......@@ -605,7 +607,7 @@ public override IOperation VisitDiscardOperation(IDiscardOperation operation, ob
public override IOperation VisitDiscardPattern(IDiscardPatternOperation operation, object argument)
{
return new DiscardPatternOperation(operation.InputType, operation.SemanticModel, operation.Syntax, operation.IsImplicit);
return new DiscardPatternOperation(operation.InputType, operation.NarrowedType, operation.SemanticModel, operation.Syntax, operation.IsImplicit);
}
public override IOperation VisitSwitchExpression(ISwitchExpressionOperation operation, object argument)
......
......@@ -2361,6 +2361,11 @@
<summary>The input type to the pattern-matching operation.</summary>
</Comments>
</Property>
<Property Name="NarrowedType" Type="ITypeSymbol">
<Comments>
<summary>The narrowed type of the pattern-matching operation.</summary>
</Comments>
</Property>
</AbstractNode>
<Node Name="IConstantPatternOperation" Base="IPatternOperation">
<Comments>
......
......@@ -699,8 +699,8 @@ internal sealed partial class WhileLoopOperation : BaseWhileLoopOperation, IWhil
internal sealed partial class ConstantPatternOperation : BaseConstantPatternOperation, IConstantPatternOperation
{
public ConstantPatternOperation(ITypeSymbol inputType, IOperation value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
this(value, inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
public ConstantPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, IOperation value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
this(value, inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{ }
}
......@@ -708,13 +708,14 @@ internal sealed partial class DeclarationPatternOperation : BasePatternOperation
{
public DeclarationPatternOperation(
ITypeSymbol inputType,
ITypeSymbol narrowedType,
ITypeSymbol matchedType,
ISymbol declaredSymbol,
bool matchesNull,
SemanticModel semanticModel,
SyntaxNode syntax,
bool isImplicit)
: this(matchedType, matchesNull, declaredSymbol, inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
: this(matchedType, matchesNull, declaredSymbol, inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{ }
}
......@@ -722,6 +723,7 @@ internal sealed partial class RecursivePatternOperation : BaseRecursivePatternOp
{
public RecursivePatternOperation(
ITypeSymbol inputType,
ITypeSymbol narrowedType,
ITypeSymbol matchedType,
ISymbol deconstructSymbol,
ImmutableArray<IPatternOperation> deconstructionSubpatterns,
......@@ -729,7 +731,7 @@ internal sealed partial class RecursivePatternOperation : BaseRecursivePatternOp
ISymbol declaredSymbol, SemanticModel semanticModel,
SyntaxNode syntax,
bool isImplicit) :
this(matchedType, deconstructSymbol, deconstructionSubpatterns, propertySubpatterns, declaredSymbol, inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
this(matchedType, deconstructSymbol, deconstructionSubpatterns, propertySubpatterns, declaredSymbol, inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{ }
}
......@@ -971,8 +973,8 @@ internal sealed partial class ConstructorBodyOperation : BaseConstructorBodyOper
internal sealed partial class DiscardPatternOperation : BasePatternOperation, IDiscardPatternOperation
{
public DiscardPatternOperation(ITypeSymbol inputType, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
this(inputType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
public DiscardPatternOperation(ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) :
this(inputType, narrowedType, semanticModel, syntax, type: null, constantValue: null, isImplicit)
{ }
}
......
......@@ -31,6 +31,7 @@ Microsoft.CodeAnalysis.Operations.IBinaryPatternOperation.OperatorKind.get -> Mi
Microsoft.CodeAnalysis.Operations.IBinaryPatternOperation.RightPattern.get -> Microsoft.CodeAnalysis.Operations.IPatternOperation
Microsoft.CodeAnalysis.Operations.INegatedPatternOperation
Microsoft.CodeAnalysis.Operations.INegatedPatternOperation.Pattern.get -> Microsoft.CodeAnalysis.Operations.IPatternOperation
Microsoft.CodeAnalysis.Operations.IPatternOperation.NarrowedType.get -> Microsoft.CodeAnalysis.ITypeSymbol
Microsoft.CodeAnalysis.Operations.IRelationalPatternOperation
Microsoft.CodeAnalysis.Operations.IRelationalPatternOperation.OperatorKind.get -> Microsoft.CodeAnalysis.Operations.BinaryOperatorKind
Microsoft.CodeAnalysis.Operations.IRelationalPatternOperation.Value.get -> Microsoft.CodeAnalysis.IOperation
......
......@@ -78,6 +78,8 @@ private void LogPatternProperties(IPatternOperation operation)
LogCommonProperties(operation);
LogString(" (");
LogType(operation.InputType, $"{nameof(operation.InputType)}");
LogString(", ");
LogType(operation.NarrowedType, $"{nameof(operation.NarrowedType)}");
}
private void LogCommonPropertiesAndNewLine(IOperation operation)
......
......@@ -1107,6 +1107,7 @@ public override void VisitInterpolation(IInterpolationOperation operation)
private void VisitPatternCommon(IPatternOperation pattern)
{
Assert.NotNull(pattern.InputType);
Assert.NotNull(pattern.NarrowedType);
Assert.Null(pattern.Type);
Assert.False(pattern.ConstantValue.HasValue);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册