Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
bae7d81c
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,发现更多精彩内容 >>
提交
bae7d81c
编写于
5月 14, 2015
作者:
N
Neal Gafter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not allow await in catch/finally un language version 5
Fixes #2725
上级
1310d8bc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
58 addition
and
16 deletion
+58
-16
src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
+20
-10
src/Compilers/CSharp/Portable/CSharpParseOptions.cs
src/Compilers/CSharp/Portable/CSharpParseOptions.cs
+7
-0
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+10
-1
src/Compilers/CSharp/Portable/CSharpResources.resx
src/Compilers/CSharp/Portable/CSharpResources.resx
+3
-0
src/Compilers/CSharp/Portable/Errors/MessageID.cs
src/Compilers/CSharp/Portable/Errors/MessageID.cs
+2
-0
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
+1
-3
src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
...ilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
+15
-2
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
浏览文件 @
bae7d81c
...
...
@@ -118,32 +118,42 @@ private bool ReportBadAwaitWithoutAsync(CSharpSyntaxNode node, DiagnosticBag dia
}
/// <summary>
/// Report diagnostics if the await expression occurs in an unsafe context.
/// Errors for await in lock statement, finally block, or catch clause are detected
/// and reported in the warnings pass.
/// Report diagnostics if the await expression occurs in a context where it is not allowed.
/// </summary>
/// <returns>True if errors were found.</returns>
private
bool
ReportBadAwaitContext
(
CSharpSyntaxNode
node
,
DiagnosticBag
diagnostics
)
{
bool
hasErrors
=
false
;
if
(
this
.
InUnsafeRegion
&&
!
this
.
Flags
.
Includes
(
BinderFlags
.
AllowAwaitInUnsafeContext
))
{
Error
(
diagnostics
,
ErrorCode
.
ERR_AwaitInUnsafeContext
,
node
);
hasErrors
=
true
;
return
true
;
}
else
if
(
this
.
Flags
.
Includes
(
BinderFlags
.
InLockBody
))
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadAwaitInLock
,
node
);
hasErrors
=
true
;
return
true
;
}
else
if
(
this
.
Flags
.
Includes
(
BinderFlags
.
InCatchFilter
))
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadAwaitInCatchFilter
,
node
);
hasErrors
=
true
;
return
true
;
}
else
if
(
this
.
Flags
.
Includes
(
BinderFlags
.
InFinallyBlock
)
&&
(
node
.
SyntaxTree
as
CSharpSyntaxTree
)?.
Options
?.
IsFeatureEnabled
(
MessageID
.
IDS_AwaitInCatchAndFinally
)
==
false
)
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadAwaitInFinally
,
node
);
return
true
;
}
else
if
(
this
.
Flags
.
Includes
(
BinderFlags
.
InCatchBlock
)
&&
(
node
.
SyntaxTree
as
CSharpSyntaxTree
)?.
Options
?.
IsFeatureEnabled
(
MessageID
.
IDS_AwaitInCatchAndFinally
)
==
false
)
{
Error
(
diagnostics
,
ErrorCode
.
ERR_BadAwaitInCatch
,
node
);
return
true
;
}
else
{
return
false
;
}
return
hasErrors
;
}
/// <summary>
...
...
src/Compilers/CSharp/Portable/CSharpParseOptions.cs
浏览文件 @
bae7d81c
...
...
@@ -196,6 +196,13 @@ public new CSharpParseOptions WithFeatures(IEnumerable<KeyValuePair<string, stri
}
}
internal
bool
IsFeatureEnabled
(
MessageID
feature
)
{
LanguageVersion
availableVersion
=
LanguageVersion
;
LanguageVersion
requiredVersion
=
feature
.
RequiredVersion
();
return
availableVersion
>=
requiredVersion
;
}
public
override
bool
Equals
(
object
obj
)
{
return
this
.
Equals
(
obj
as
CSharpParseOptions
);
...
...
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
浏览文件 @
bae7d81c
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.0
// Runtime Version:4.0.30319.
4200
0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
...
...
@@ -8692,6 +8692,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to await in catch blocks and finally blocks.
/// </summary>
internal static string IDS_AwaitInCatchAndFinally {
get {
return ResourceManager.GetString("IDS_AwaitInCatchAndFinally", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to collection.
/// </summary>
...
...
src/Compilers/CSharp/Portable/CSharpResources.resx
浏览文件 @
bae7d81c
...
...
@@ -4594,6 +4594,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data
name=
"IDS_FeatureInterpolatedStrings"
xml:space=
"preserve"
>
<value>
interpolated strings
</value>
</data>
<data
name=
"IDS_AwaitInCatchAndFinally"
xml:space=
"preserve"
>
<value>
await in catch blocks and finally blocks
</value>
</data>
<data
name=
"ERR_UnescapedCurly"
xml:space=
"preserve"
>
<value>
A '{0}' character must be escaped (by doubling) in an interpolated string.
</value>
</data>
...
...
src/Compilers/CSharp/Portable/Errors/MessageID.cs
浏览文件 @
bae7d81c
...
...
@@ -110,6 +110,7 @@ internal enum MessageID
IDS_FeatureUsingStatic
=
MessageBase
+
12701
,
IDS_FeatureInterpolatedStrings
=
MessageBase
+
12702
,
IDS_OperationCausedStackOverflow
=
MessageBase
+
12703
,
IDS_AwaitInCatchAndFinally
=
MessageBase
+
12704
,
}
...
...
@@ -161,6 +162,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case
MessageID
.
IDS_FeatureDictionaryInitializer
:
case
MessageID
.
IDS_FeatureUsingStatic
:
case
MessageID
.
IDS_FeatureInterpolatedStrings
:
case
MessageID
.
IDS_AwaitInCatchAndFinally
:
return
LanguageVersion
.
CSharp6
;
// C# 5 features.
...
...
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
浏览文件 @
bae7d81c
...
...
@@ -1056,9 +1056,7 @@ protected TNode CheckFeatureAvailability<TNode>(TNode node, MessageID feature, b
protected
bool
IsFeatureEnabled
(
MessageID
feature
)
{
LanguageVersion
availableVersion
=
this
.
Options
.
LanguageVersion
;
LanguageVersion
requiredVersion
=
feature
.
RequiredVersion
();
return
availableVersion
>=
requiredVersion
;
return
this
.
Options
.
IsFeatureEnabled
(
feature
);
}
}
}
src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
浏览文件 @
bae7d81c
...
...
@@ -890,7 +890,15 @@ class Test
}
}
}"
;
CreateCompilationWithMscorlib45
(
source
).
VerifyDiagnostics
();
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
)).
VerifyDiagnostics
(
// (20,17): error CS1984: Cannot await in the body of a finally clause
// await Task.Factory.StartNew(() => { });
Diagnostic
(
ErrorCode
.
ERR_BadAwaitInFinally
,
"await Task.Factory.StartNew(() => { })"
).
WithLocation
(
20
,
17
),
// (30,17): error CS1984: Cannot await in the body of a finally clause
// await Task.Factory.StartNew(() => { });
Diagnostic
(
ErrorCode
.
ERR_BadAwaitInFinally
,
"await Task.Factory.StartNew(() => { })"
).
WithLocation
(
30
,
17
)
);
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp6
)).
VerifyDiagnostics
();
}
[
Fact
]
...
...
@@ -914,7 +922,12 @@ class Test
}
}
}"
;
CreateCompilationWithMscorlib45
(
source
).
VerifyDiagnostics
();
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
)).
VerifyDiagnostics
(
// (12,13): error CS1985: Cannot await in a catch clause
// await Task.Factory.StartNew(() => { });
Diagnostic
(
ErrorCode
.
ERR_BadAwaitInCatch
,
"await Task.Factory.StartNew(() => { })"
).
WithLocation
(
12
,
13
)
);
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
TestOptions
.
Regular
.
WithLanguageVersion
(
LanguageVersion
.
CSharp6
)).
VerifyDiagnostics
();
}
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录