Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
31381123
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
31381123
编写于
7月 06, 2020
作者:
N
Neal Gafter
提交者:
GitHub
7月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address review comments from #33178 documented in comment stream in #33175 (#45454)
上级
4c0ed4e4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
285 addition
and
13 deletion
+285
-13
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IIsPatternExpression.cs
...ration/IOperation/IOperationTests_IIsPatternExpression.cs
+273
-0
src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
...ilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
+4
-4
src/Compilers/Core/Portable/Operations/OperationCloner.cs
src/Compilers/Core/Portable/Operations/OperationCloner.cs
+4
-4
src/Compilers/Core/Portable/Operations/OperationNodes.cs
src/Compilers/Core/Portable/Operations/OperationNodes.cs
+3
-3
src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs
...t/Utilities/Portable/Compilation/OperationTreeVerifier.cs
+1
-1
src/Test/Utilities/Portable/Compilation/TestOperationVisitor.cs
...st/Utilities/Portable/Compilation/TestOperationVisitor.cs
+0
-1
未找到文件。
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IIsPatternExpression.cs
浏览文件 @
31381123
...
...
@@ -1182,6 +1182,279 @@ void M1(object o, bool b)
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_04
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { A: var a }/*</bind>*/;
}
}
class D
{
public event System.Action A;
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0154: The property or indexer 'A' cannot be used in this context because it lacks the get accessor
// _ = /*<bind>*/o is D { A: var a }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_PropertyLacksGet
,
"A"
).
WithArguments
(
"A"
).
WithLocation
(
6
,
32
),
// (11,32): warning CS0067: The event 'D.A' is never used
// public event System.Action A;
Diagnostic
(
ErrorCode
.
WRN_UnreferencedEvent
,
"A"
).
WithArguments
(
"D.A"
).
WithLocation
(
11
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { A: var a }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { A: var a }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'A: var a')
Member:
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: 'A')
Children(0)
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var a') (InputType: ?, DeclaredSymbol: ?? a, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_05
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { B: var b }/*</bind>*/;
}
}
class D
{
public void B() { }
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0154: The property or indexer 'B' cannot be used in this context because it lacks the get accessor
// _ = /*<bind>*/o is D { B: var b }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_PropertyLacksGet
,
"B"
).
WithArguments
(
"B"
).
WithLocation
(
6
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { B: var b }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { B: var b }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'B: var b')
Member:
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: 'B')
Children(0)
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var b') (InputType: ?, DeclaredSymbol: ?? b, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_06
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { C: var c }/*</bind>*/;
}
}
class D
{
public class C { }
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0572: 'C': cannot reference a type through an expression; try 'D.C' instead
// _ = /*<bind>*/o is D { C: var c }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_BadTypeReference
,
"C"
).
WithArguments
(
"C"
,
"D.C"
).
WithLocation
(
6
,
32
),
// (6,32): error CS0154: The property or indexer 'C' cannot be used in this context because it lacks the get accessor
// _ = /*<bind>*/o is D { C: var c }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_PropertyLacksGet
,
"C"
).
WithArguments
(
"C"
).
WithLocation
(
6
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { C: var c }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { C: var c }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'C: var c')
Member:
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: 'C')
Children(0)
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var c') (InputType: ?, DeclaredSymbol: ?? c, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_07
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { X: var x }/*</bind>*/;
}
}
class D
{
public const int X = 3;
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0176: Member 'D.X' cannot be accessed with an instance reference; qualify it with a type name instead
// _ = /*<bind>*/o is D { X: var x }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_ObjectProhibited
,
"X"
).
WithArguments
(
"D.X"
).
WithLocation
(
6
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { X: var x }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { X: var x }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'X: var x')
Member:
IFieldReferenceOperation: System.Int32 D.X (Static) (OperationKind.FieldReference, Type: System.Int32, Constant: 3, IsInvalid) (Syntax: 'X')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: PatternInput) (OperationKind.InstanceReference, Type: D, Constant: 3, IsInvalid, IsImplicit) (Syntax: 'X')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var x') (InputType: ?, DeclaredSymbol: ?? x, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_08
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { X: var x }/*</bind>*/;
}
}
class D
{
public static int X = 3;
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0176: Member 'D.X' cannot be accessed with an instance reference; qualify it with a type name instead
// _ = /*<bind>*/o is D { X: var x }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_ObjectProhibited
,
"X"
).
WithArguments
(
"D.X"
).
WithLocation
(
6
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { X: var x }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { X: var x }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'X: var x')
Member:
IFieldReferenceOperation: System.Int32 D.X (Static) (OperationKind.FieldReference, Type: System.Int32, IsInvalid) (Syntax: 'X')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: PatternInput) (OperationKind.InstanceReference, Type: D, IsInvalid, IsImplicit) (Syntax: 'X')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var x') (InputType: ?, DeclaredSymbol: ?? x, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_BadRecursivePattern_09
()
{
var
source
=
@"
class C
{
void M1(object o)
{
_ = /*<bind>*/o is D { X: var x }/*</bind>*/;
}
}
class D
{
public static int X => 3;
}
"
;
var
compilation
=
CreateCompilation
(
source
);
compilation
.
VerifyDiagnostics
(
// (6,32): error CS0176: Member 'D.X' cannot be accessed with an instance reference; qualify it with a type name instead
// _ = /*<bind>*/o is D { X: var x }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_ObjectProhibited
,
"X"
).
WithArguments
(
"D.X"
).
WithLocation
(
6
,
32
)
);
var
expectedOperationTree
=
@"
IIsPatternOperation (OperationKind.IsPattern, Type: System.Boolean, IsInvalid) (Syntax: 'o is D { X: var x }')
Value:
IParameterReferenceOperation: o (OperationKind.ParameterReference, Type: System.Object) (Syntax: 'o')
Pattern:
IRecursivePatternOperation (OperationKind.RecursivePattern, Type: null, IsInvalid) (Syntax: 'D { X: var x }') (InputType: System.Object, DeclaredSymbol: null, MatchedType: D, DeconstructSymbol: null)
DeconstructionSubpatterns (0)
PropertySubpatterns (1):
IPropertySubpatternOperation (OperationKind.PropertySubpattern, Type: null, IsInvalid) (Syntax: 'X: var x')
Member:
IPropertyReferenceOperation: System.Int32 D.X { get; } (Static) (OperationKind.PropertyReference, Type: System.Int32, IsInvalid) (Syntax: 'X')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: PatternInput) (OperationKind.InstanceReference, Type: D, IsInvalid, IsImplicit) (Syntax: 'X')
Pattern:
IDeclarationPatternOperation (OperationKind.DeclarationPattern, Type: null) (Syntax: 'var x') (InputType: ?, DeclaredSymbol: ?? x, MatchesNull: True)
"
;
VerifyOperationTreeForTest
<
IsPatternExpressionSyntax
>(
compilation
,
expectedOperationTree
);
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
,
CompilerFeature
.
Dataflow
,
CompilerFeature
.
Patterns
)]
[
Fact
]
public
void
IsPattern_ControlFlowInPattern
()
...
...
src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
浏览文件 @
31381123
...
...
@@ -6797,11 +6797,11 @@ public override IOperation VisitRecursivePattern(IRecursivePatternOperation oper
public
override
IOperation
VisitPropertySubpattern
(
IPropertySubpatternOperation
operation
,
int
?
argument
)
{
return
new
PropertySubpatternOperation
(
semanticModel
:
null
,
operation
.
Syntax
,
IsImplicit
(
operation
),
Visit
(
operation
.
Member
),
(
IPatternOperation
)
Visit
(
operation
.
Pattern
));
(
IPatternOperation
)
Visit
(
operation
.
Pattern
),
semanticModel
:
null
,
syntax
:
operation
.
Syntax
,
isImplicit
:
IsImplicit
(
operation
));
}
public
override
IOperation
VisitDelegateCreation
(
IDelegateCreationOperation
operation
,
int
?
captureIdForResult
)
...
...
src/Compilers/Core/Portable/Operations/OperationCloner.cs
浏览文件 @
31381123
...
...
@@ -560,11 +560,11 @@ public override IOperation VisitRecursivePattern(IRecursivePatternOperation oper
public
override
IOperation
VisitPropertySubpattern
(
IPropertySubpatternOperation
operation
,
object
argument
)
{
return
new
PropertySubpatternOperation
(
semanticModel
:
((
Operation
)
operation
).
OwningSemanticModel
,
operation
.
Syntax
,
operation
.
IsImplicit
,
Visit
(
operation
.
Member
),
Visit
(
operation
.
Pattern
));
Visit
(
operation
.
Pattern
),
semanticModel
:
((
Operation
)
operation
).
OwningSemanticModel
,
syntax
:
operation
.
Syntax
,
isImplicit
:
operation
.
IsImplicit
);
}
public
override
IOperation
VisitPatternCaseClause
(
IPatternCaseClauseOperation
operation
,
object
argument
)
...
...
src/Compilers/Core/Portable/Operations/OperationNodes.cs
浏览文件 @
31381123
...
...
@@ -736,11 +736,11 @@ internal sealed partial class RecursivePatternOperation : BaseRecursivePatternOp
internal
sealed
partial
class
PropertySubpatternOperation
:
BasePropertySubpatternOperation
{
public
PropertySubpatternOperation
(
IOperation
member
,
IPatternOperation
pattern
,
SemanticModel
semanticModel
,
SyntaxNode
syntax
,
bool
isImplicit
,
IOperation
member
,
IPatternOperation
pattern
)
:
bool
isImplicit
)
:
this
(
member
,
pattern
,
semanticModel
,
syntax
,
type
:
null
,
constantValue
:
null
,
isImplicit
)
{
}
}
...
...
src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs
浏览文件 @
31381123
...
...
@@ -964,7 +964,7 @@ public override void VisitInstanceReference(IInstanceReferenceOperation operatio
{
if
(
operation
.
Parent
is
IMemberReferenceOperation
memberReference
&&
memberReference
.
Instance
==
operation
)
{
Assert
.
False
(
memberReference
.
Member
.
IsStatic
);
Assert
.
False
(
memberReference
.
Member
.
IsStatic
&&
!
operation
.
HasErrors
(
this
.
_compilation
)
);
}
else
if
(
operation
.
Parent
is
IInvocationOperation
invocation
&&
invocation
.
Instance
==
operation
)
{
...
...
src/Test/Utilities/Portable/Compilation/TestOperationVisitor.cs
浏览文件 @
31381123
...
...
@@ -1253,7 +1253,6 @@ public override void VisitPropertySubpattern(IPropertySubpatternOperation operat
{
case
IFieldSymbol
field
:
case
IPropertySymbol
prop
:
case
IErrorTypeSymbol
error
:
break
;
case
var
symbol
:
Assert
.
True
(
false
,
$"Unexpected symbol
{
symbol
}
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录