Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
05f6d3f5
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,发现更多精彩内容 >>
提交
05f6d3f5
编写于
11月 15, 2016
作者:
J
Julien Couvreur
提交者:
GitHub
11月 15, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for restricted types in deconstruction in async method (#15258)
上级
0d5e74c2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
103 addition
and
21 deletion
+103
-21
src/Compilers/CSharp/Portable/Binder/Binder_Deconstruct.cs
src/Compilers/CSharp/Portable/Binder/Binder_Deconstruct.cs
+1
-0
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+16
-6
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
+2
-6
src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
+1
-4
src/Compilers/CSharp/Portable/BoundTree/DeconstructionVariablePendingInference.cs
...table/BoundTree/DeconstructionVariablePendingInference.cs
+5
-0
src/Compilers/CSharp/Portable/BoundTree/OutVariablePendingInference.cs
.../CSharp/Portable/BoundTree/OutVariablePendingInference.cs
+3
-5
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
...ilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
+75
-0
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Deconstruct.cs
浏览文件 @
05f6d3f5
...
...
@@ -745,6 +745,7 @@ private static void FlattenDeconstructVariables(ArrayBuilder<DeconstructionVaria
if
(!
isVar
)
{
CheckRestrictedTypeInAsync
(
this
.
ContainingMemberOrLambda
,
declType
,
diagnostics
,
typeSyntax
);
return
new
BoundLocal
(
designation
,
localSymbol
,
constantValueOpt
:
null
,
type
:
declType
,
hasErrors
:
hasErrors
);
}
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
05f6d3f5
...
...
@@ -2120,12 +2120,7 @@ private BoundExpression BindOutVariableArgument(DeclarationExpressionSyntax decl
return
new
OutVariablePendingInference
(
declarationExpression
,
localSymbol
,
null
);
}
if
(
this
.
ContainingMemberOrLambda
.
Kind
==
SymbolKind
.
Method
&&
((
MethodSymbol
)
this
.
ContainingMemberOrLambda
).
IsAsync
&&
declType
.
IsRestrictedType
())
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadSpecialByRefLocal
,
typeSyntax
,
declType
);
}
CheckRestrictedTypeInAsync
(
this
.
ContainingMemberOrLambda
,
declType
,
diagnostics
,
typeSyntax
);
return
new
BoundLocal
(
declarationExpression
,
localSymbol
,
constantValueOpt
:
null
,
type
:
declType
);
}
...
...
@@ -2159,6 +2154,21 @@ private BoundExpression BindOutVariableArgument(DeclarationExpressionSyntax decl
expressionVariableField
,
null
,
LookupResultKind
.
Viable
,
fieldType
);
}
/// <summary>
/// Returns true if a bad special by ref local was found.
/// </summary>
internal
static
bool
CheckRestrictedTypeInAsync
(
Symbol
containingSymbol
,
TypeSymbol
type
,
DiagnosticBag
diagnostics
,
SyntaxNode
syntax
)
{
if
(
containingSymbol
.
Kind
==
SymbolKind
.
Method
&&
((
MethodSymbol
)
containingSymbol
).
IsAsync
&&
type
.
IsRestrictedType
())
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadSpecialByRefLocal
,
syntax
,
type
);
return
true
;
}
return
false
;
}
internal
GlobalExpressionVariable
LookupDeclaredField
(
SingleVariableDesignationSyntax
variableDesignator
)
{
return
LookupDeclaredField
(
variableDesignator
,
variableDesignator
.
Identifier
.
ValueText
);
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
浏览文件 @
05f6d3f5
...
...
@@ -291,13 +291,9 @@ internal BoundExpression ConvertPatternExpression(TypeSymbol inputType, CSharpSy
// Check for variable declaration errors.
hasErrors
|=
localSymbol
.
ScopeBinder
.
ValidateDeclarationNameConflictsInScope
(
localSymbol
,
diagnostics
);
if
(
this
.
ContainingMemberOrLambda
.
Kind
==
SymbolKind
.
Method
&&
((
MethodSymbol
)
this
.
ContainingMemberOrLambda
).
IsAsync
&&
declType
.
IsRestrictedType
()
&&
!
hasErrors
)
if
(!
hasErrors
)
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadSpecialByRefLocal
,
typeSyntax
,
declType
);
hasErrors
=
true
;
hasErrors
=
CheckRestrictedTypeInAsync
(
this
.
ContainingMemberOrLambda
,
declType
,
diagnostics
,
typeSyntax
);
}
return
new
BoundDeclarationPattern
(
node
,
localSymbol
,
boundDeclType
,
isVar
,
hasErrors
);
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
浏览文件 @
05f6d3f5
...
...
@@ -882,11 +882,8 @@ private TypeSymbol BindVariableType(CSharpSyntaxNode declarationNode, Diagnostic
}
}
if
(
this
.
ContainingMemberOrLambda
.
Kind
==
SymbolKind
.
Method
&&
((
MethodSymbol
)
this
.
ContainingMemberOrLambda
).
IsAsync
&&
declTypeOpt
.
IsRestrictedType
())
if
(
CheckRestrictedTypeInAsync
(
this
.
ContainingMemberOrLambda
,
declTypeOpt
,
localDiagnostics
,
typeSyntax
))
{
Error
(
localDiagnostics
,
ErrorCode
.
ERR_BadSpecialByRefLocal
,
typeSyntax
,
declTypeOpt
);
hasErrors
=
true
;
}
...
...
src/Compilers/CSharp/Portable/BoundTree/DeconstructionVariablePendingInference.cs
浏览文件 @
05f6d3f5
...
...
@@ -29,6 +29,11 @@ public BoundExpression SetInferredType(TypeSymbol type, Binder binderOpt, Diagno
{
ReportInferenceFailure
(
diagnostics
);
}
else
{
Binder
.
CheckRestrictedTypeInAsync
(
local
.
ContainingSymbol
,
type
,
diagnostics
,
this
.
Syntax
);
}
local
.
SetType
(
type
);
return
new
BoundLocal
(
this
.
Syntax
,
local
,
constantValueOpt
:
null
,
type
:
type
,
hasErrors
:
this
.
HasErrors
||
inferenceFailed
);
...
...
src/Compilers/CSharp/Portable/BoundTree/OutVariablePendingInference.cs
浏览文件 @
05f6d3f5
...
...
@@ -39,12 +39,10 @@ private BoundExpression SetInferredType(TypeSymbol type, Binder binderOpt, Diagn
{
ReportInferenceFailure
(
diagnosticsOpt
);
}
else
if
(
localSymbol
.
ContainingSymbol
.
Kind
==
SymbolKind
.
Method
&&
((
MethodSymbol
)
localSymbol
.
ContainingSymbol
).
IsAsync
&&
type
.
IsRestrictedType
())
else
{
var
declaration
=
(
DeclarationExpressionSyntax
)
this
.
Syntax
;
Binder
.
Error
(
diagnosticsOpt
,
ErrorCode
.
ERR_BadSpecialByRefLocal
,
declaration
.
Type
,
type
);
TypeSyntax
typeSyntax
=
((
DeclarationExpressionSyntax
)
Syntax
).
Type
;
Binder
.
CheckRestrictedTypeInAsync
(
localSymbol
.
ContainingSymbol
,
type
,
diagnosticsOpt
,
typeSyntax
);
}
}
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
浏览文件 @
05f6d3f5
...
...
@@ -1163,6 +1163,81 @@ public void Deconstruct(out int a, out int b)
);
}
[
Fact
]
public
void
NoArgIteratorTypeInAsync
()
{
string
source
=
@"
using System;
class C
{
public async void M()
{
(int x, var (err1, y)) = (0, new C());
(ArgIterator err2, var err3) = M2();
foreach ((ArgIterator err4, var err5) in new[] { M2() })
{
}
}
public static (ArgIterator, ArgIterator) M2()
{
return (default(ArgIterator), default(ArgIterator));
}
public void Deconstruct(out ArgIterator a, out int b)
{
a = default(ArgIterator);
b = 2;
}
public void M3()
{
(int x, var (err1, y)) = (0, new C());
(ArgIterator err2, var err3) = M2();
foreach ((ArgIterator err4, var err5) in new[] { M2() })
{
}
}
}
"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
references
:
new
[]
{
ValueTupleRef
,
SystemRuntimeFacadeRef
});
comp
.
VerifyDiagnostics
(
// (14,20): error CS0610: Field or property cannot be of type 'ArgIterator'
// public static (ArgIterator, ArgIterator) M2()
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"ArgIterator"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
14
,
20
),
// (14,33): error CS0610: Field or property cannot be of type 'ArgIterator'
// public static (ArgIterator, ArgIterator) M2()
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"ArgIterator"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
14
,
33
),
// (18,29): error CS1601: Cannot make reference to variable of type 'ArgIterator'
// public void Deconstruct(out ArgIterator a, out int b)
Diagnostic
(
ErrorCode
.
ERR_MethodArgCantBeRefAny
,
"out ArgIterator a"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
18
,
29
),
// (7,22): error CS4012: Parameters or locals of type 'ArgIterator' cannot be declared in async methods or lambda expressions.
// (int x, var (err1, y)) = (0, new C());
Diagnostic
(
ErrorCode
.
ERR_BadSpecialByRefLocal
,
"err1"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
7
,
22
),
// (8,10): error CS4012: Parameters or locals of type 'ArgIterator' cannot be declared in async methods or lambda expressions.
// (ArgIterator err2, var err3) = M2();
Diagnostic
(
ErrorCode
.
ERR_BadSpecialByRefLocal
,
"ArgIterator"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
8
,
10
),
// (8,32): error CS4012: Parameters or locals of type 'ArgIterator' cannot be declared in async methods or lambda expressions.
// (ArgIterator err2, var err3) = M2();
Diagnostic
(
ErrorCode
.
ERR_BadSpecialByRefLocal
,
"err3"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
8
,
32
),
// (9,19): error CS4012: Parameters or locals of type 'ArgIterator' cannot be declared in async methods or lambda expressions.
// foreach ((ArgIterator err4, var err5) in new[] { M2() })
Diagnostic
(
ErrorCode
.
ERR_BadSpecialByRefLocal
,
"ArgIterator"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
9
,
19
),
// (9,41): error CS4012: Parameters or locals of type 'ArgIterator' cannot be declared in async methods or lambda expressions.
// foreach ((ArgIterator err4, var err5) in new[] { M2() })
Diagnostic
(
ErrorCode
.
ERR_BadSpecialByRefLocal
,
"err5"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
9
,
41
),
// (5,23): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
// public async void M()
Diagnostic
(
ErrorCode
.
WRN_AsyncLacksAwaits
,
"M"
).
WithLocation
(
5
,
23
),
// (16,17): error CS0610: Field or property cannot be of type 'ArgIterator'
// return (default(ArgIterator), default(ArgIterator));
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"default(ArgIterator)"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
16
,
17
),
// (16,39): error CS0610: Field or property cannot be of type 'ArgIterator'
// return (default(ArgIterator), default(ArgIterator));
Diagnostic
(
ErrorCode
.
ERR_FieldCantBeRefAny
,
"default(ArgIterator)"
).
WithArguments
(
"System.ArgIterator"
).
WithLocation
(
16
,
39
)
);
}
[
Fact
]
public
void
MixedDeconstructionCannotBeParsed
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录