Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1ff04c56
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,发现更多精彩内容 >>
提交
1ff04c56
编写于
12月 12, 2014
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change exception filter keyword if ----> when.
***NO_CI*** (changeset 1385867)
上级
789d7289
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
125 addition
and
116 deletion
+125
-116
Src/Compilers/CSharp/Portable/CodeGen/EmitStatement.cs
Src/Compilers/CSharp/Portable/CodeGen/EmitStatement.cs
+1
-1
Src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+4
-3
Src/Compilers/CSharp/Portable/Syntax/Syntax.xml
Src/Compilers/CSharp/Portable/Syntax/Syntax.xml
+2
-2
Src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
Src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
+1
-0
Src/Compilers/CSharp/Portable/Syntax/SyntaxKindFacts.cs
Src/Compilers/CSharp/Portable/Syntax/SyntaxKindFacts.cs
+6
-1
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs
...Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs
+6
-6
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenClosureLambdaTests.cs
...ers/CSharp/Test/Emit/CodeGen/CodeGenClosureLambdaTests.cs
+10
-10
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs
+14
-14
Src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs
...rp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs
+1
-1
Src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
Src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
+6
-8
Src/Compilers/CSharp/Test/Semantic/FlowAnalysis/FlowTests.cs
Src/Compilers/CSharp/Test/Semantic/FlowAnalysis/FlowTests.cs
+10
-10
Src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
...ilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
+3
-3
Src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
Src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
+1
-1
Src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
...lers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
+26
-24
Src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
...Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
+1
-1
Src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+33
-31
未找到文件。
Src/Compilers/CSharp/Portable/CodeGen/EmitStatement.cs
浏览文件 @
1ff04c56
...
...
@@ -759,7 +759,7 @@ private void EmitTryStatement(BoundTryStatement statement, bool emitCatchesOnly
/// {
/// TryBlock
/// }
/// catch (ExceptionType ex)
if
(Condition)
/// catch (ExceptionType ex)
when
(Condition)
/// {
/// Handler
/// }
...
...
Src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
1ff04c56
...
...
@@ -7194,16 +7194,17 @@ private CatchClauseSyntax ParseCatchClause(bool hasCatchAll)
CatchFilterClauseSyntax
filter
=
null
;
if
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
If
Keyword
)
if
(
this
.
CurrentToken
.
ContextualKind
==
SyntaxKind
.
When
Keyword
)
{
var
ifKeyword
=
CheckFeatureAvailability
(
this
.
EatToken
(),
MessageID
.
IDS_FeatureExceptionFilter
);
var
whenKeyword
=
this
.
EatContextualToken
(
SyntaxKind
.
WhenKeyword
);
whenKeyword
=
CheckFeatureAvailability
(
whenKeyword
,
MessageID
.
IDS_FeatureExceptionFilter
);
this
.
termState
|=
TerminatorState
.
IsEndOfilterClause
;
var
openParen
=
this
.
EatToken
(
SyntaxKind
.
OpenParenToken
);
var
filterExpression
=
this
.
ParseExpression
();
this
.
termState
=
saveTerm
;
var
closeParen
=
this
.
EatToken
(
SyntaxKind
.
CloseParenToken
);
filter
=
syntaxFactory
.
CatchFilterClause
(
if
Keyword
,
openParen
,
filterExpression
,
closeParen
);
filter
=
syntaxFactory
.
CatchFilterClause
(
when
Keyword
,
openParen
,
filterExpression
,
closeParen
);
}
this
.
termState
|=
TerminatorState
.
IsEndOfCatchBlock
;
...
...
Src/Compilers/CSharp/Portable/Syntax/Syntax.xml
浏览文件 @
1ff04c56
...
...
@@ -2108,8 +2108,8 @@
</Node>
<Node
Name=
"CatchFilterClauseSyntax"
Base=
"CSharpSyntaxNode"
>
<Kind
Name=
"CatchFilterClause"
/>
<Field
Name=
"
If
Keyword"
Type=
"SyntaxToken"
>
<Kind
Name=
"
If
Keyword"
/>
<Field
Name=
"
When
Keyword"
Type=
"SyntaxToken"
>
<Kind
Name=
"
When
Keyword"
/>
</Field>
<Field
Name=
"OpenParenToken"
Type=
"SyntaxToken"
>
<Kind
Name=
"OpenParenToken"
/>
...
...
Src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
浏览文件 @
1ff04c56
...
...
@@ -191,6 +191,7 @@ public enum SyntaxKind : ushort
NameOfKeyword
=
8434
,
AsyncKeyword
=
8435
,
AwaitKeyword
=
8436
,
WhenKeyword
=
8437
,
// additional preprocessor keywords
ElifKeyword
=
8467
,
...
...
Src/Compilers/CSharp/Portable/Syntax/SyntaxKindFacts.cs
浏览文件 @
1ff04c56
...
...
@@ -1026,7 +1026,7 @@ public static SyntaxKind GetPreprocessorKeywordKind(string text)
public
static
IEnumerable
<
SyntaxKind
>
GetContextualKeywordKinds
()
{
for
(
int
i
=
(
int
)
SyntaxKind
.
YieldKeyword
;
i
<=
(
int
)
SyntaxKind
.
Await
Keyword
;
i
++)
for
(
int
i
=
(
int
)
SyntaxKind
.
YieldKeyword
;
i
<=
(
int
)
SyntaxKind
.
When
Keyword
;
i
++)
{
yield
return
(
SyntaxKind
)
i
;
}
...
...
@@ -1068,6 +1068,7 @@ public static bool IsContextualKeyword(SyntaxKind kind)
case
SyntaxKind
.
NameOfKeyword
:
case
SyntaxKind
.
AsyncKeyword
:
case
SyntaxKind
.
AwaitKeyword
:
case
SyntaxKind
.
WhenKeyword
:
return
true
;
default
:
return
false
;
...
...
@@ -1163,6 +1164,8 @@ public static SyntaxKind GetContextualKeywordKind(string text)
return
SyntaxKind
.
AsyncKeyword
;
case
"await"
:
return
SyntaxKind
.
AwaitKeyword
;
case
"when"
:
return
SyntaxKind
.
WhenKeyword
;
case
"nameof"
:
return
SyntaxKind
.
NameOfKeyword
;
default
:
...
...
@@ -1556,6 +1559,8 @@ public static string GetText(SyntaxKind kind)
return
"async"
;
case
SyntaxKind
.
AwaitKeyword
:
return
"await"
;
case
SyntaxKind
.
WhenKeyword
:
return
"when"
;
case
SyntaxKind
.
NameOfKeyword
:
return
"nameof"
;
default
:
...
...
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncEHTests.cs
浏览文件 @
1ff04c56
...
...
@@ -1235,13 +1235,13 @@ static async Task<int> G()
{
x = x / x;
}
catch
if
(x != 0)
catch
when
(x != 0)
{
x = await F();
throw;
}
}
catch(Exception ex)
if
(x == 0 && ((ex = new Exception(""hello"")) != null))
catch(Exception ex)
when
(x == 0 && ((ex = new Exception(""hello"")) != null))
{
x = await F();
System.Console.WriteLine(ex.Message);
...
...
@@ -1294,12 +1294,12 @@ static async Task<int> G()
{
x = x / x;
}
catch(Exception ex)
if
(T(()=>ex.Message == null, ref ex))
catch(Exception ex)
when
(T(()=>ex.Message == null, ref ex))
{
x = await F();
System.Console.WriteLine(ex.Message);
}
catch(Exception ex)
if
(T(()=>ex.Message != null, ref ex))
catch(Exception ex)
when
(T(()=>ex.Message != null, ref ex))
{
x = await F();
System.Console.WriteLine(ex.Message);
...
...
@@ -1351,7 +1351,7 @@ static async Task<int> G()
{
x = x / await F(0);
}
catch (DivideByZeroException)
if
(i < 3)
catch (DivideByZeroException)
when
(i < 3)
{
await Task.Yield();
continue;
...
...
@@ -1434,7 +1434,7 @@ static Func<Task<int>> G()
{
x = x / await F(0);
}
catch (DivideByZeroException)
if
(i < 3)
catch (DivideByZeroException)
when
(i < 3)
{
await Task.Yield();
continue;
...
...
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenClosureLambdaTests.cs
浏览文件 @
1ff04c56
...
...
@@ -640,7 +640,7 @@ static void Main()
{
throw new Exception(""xxx"");
}
catch (Exception e)
if
(new Func<Exception, bool>(x => x.Message == s)(e))
catch (Exception e)
when
(new Func<Exception, bool>(x => x.Message == s)(e))
{
Console.Write(""pass"");
}
...
...
@@ -664,7 +664,7 @@ static void Main()
{
throw new Exception(""xxx"");
}
catch (Exception e)
if
(new Func<Exception, bool>(x => x.Message == s)(e))
catch (Exception e)
when
(new Func<Exception, bool>(x => x.Message == s)(e))
{
Console.Write(s + ""pass"");
}
...
...
@@ -752,7 +752,7 @@ static void Main()
{
throw new Exception(""fail"");
}
catch (Exception ex)
if
(Foo(() => { ex = new Exception(""pass""); }))
catch (Exception ex)
when
(Foo(() => { ex = new Exception(""pass""); }))
{
Console.Write(ex.Message);
}
...
...
@@ -828,11 +828,11 @@ static void Main()
{
throw new Exception(""fail"");
}
catch (ArgumentException ex)
if
(Foo(() => { ex = new ArgumentException(""fail""); }))
catch (ArgumentException ex)
when
(Foo(() => { ex = new ArgumentException(""fail""); }))
{
Console.Write(ex.Message);
}
catch (Exception ex)
if
(Foo(() => { ex = new Exception(""pass""); }))
catch (Exception ex)
when
(Foo(() => { ex = new Exception(""pass""); }))
{
Console.Write(ex.Message);
}
...
...
@@ -855,7 +855,7 @@ static void Main()
{
throw new Exception(""xxx"");
}
catch (Exception e)
if
(new Func<bool>(() => e.Message == ""xxx"")())
catch (Exception e)
when
(new Func<bool>(() => e.Message == ""xxx"")())
{
Console.Write(""pass"");
}
...
...
@@ -929,7 +929,7 @@ static void Main()
{
throw new IOException(""xxx"");
}
catch (T e)
if
(e.Message == ""xxx"")
catch (T e)
when
(e.Message == ""xxx"")
{
Console.Write(""pass"");
}
...
...
@@ -1001,7 +1001,7 @@ static void Main()
{
throw new IOException(""xy"");
}
catch (T e)
if
(new Func<bool>(() => e.Message == x + y)())
catch (T e)
when
(new Func<bool>(() => e.Message == x + y)())
{
Console.Write(""pass_"" + x + y);
}
...
...
@@ -1099,7 +1099,7 @@ static void Main()
{
throw new IOException(""a"");
}
catch (T e1)
if
(new Func<bool>(() =>
catch (T e1)
when
(new Func<bool>(() =>
{
string z = ""z"";
...
...
@@ -1107,7 +1107,7 @@ static void Main()
{
throw new IOException(""xyz"");
}
catch (T e2)
if
(e2.Message == x + y + z)
catch (T e2)
when
(e2.Message == x + y + z)
{
return true;
}
...
...
Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTryFinally.cs
浏览文件 @
1ff04c56
...
...
@@ -454,7 +454,7 @@ static void Main()
{
throw new Exception(""hello"");
}
catch (Exception ex1)
if
(ex1.Message == null)
catch (Exception ex1)
when
(ex1.Message == null)
{
}
...
...
@@ -462,7 +462,7 @@ static void Main()
{
throw new Exception(""bye"");
}
catch (Exception ex2)
if
(F(ex2, ex2))
catch (Exception ex2)
when
(F(ex2, ex2))
{
}
}
...
...
@@ -548,7 +548,7 @@ static void Main()
{
throw new Exception(""bye"");
}
catch (Exception ex)
if
(F(ex, ex))
catch (Exception ex)
when
(F(ex, ex))
{
Console.WriteLine(ex);
}
...
...
@@ -614,7 +614,7 @@ static void Main()
{
throw new Exception(""bye"");
}
catch (Exception ex)
if
(F(ref ex))
catch (Exception ex)
when
(F(ref ex))
{
Console.WriteLine(ex);
}
...
...
@@ -679,7 +679,7 @@ class Program
{
throw new Exception(""bye"");
}
catch (T ex)
if
(F(ex, ex))
catch (T ex)
when
(F(ex, ex))
{
Console.WriteLine(ex);
}
...
...
@@ -779,7 +779,7 @@ class C
{
throw new IOException(""Hi"");
}
catch (E e)
if
(new Func<bool>(() => e.Message != null)())
catch (E e)
when
(new Func<bool>(() => e.Message != null)())
{
( (Action) delegate { Console.WriteLine(e.Message); })();
}
...
...
@@ -1421,7 +1421,7 @@ static void Main()
Console.Write(""Try"");
x = x / x;
}
catch
if
(Filter())
catch
when
(Filter())
{
Console.Write(""Catch"");
}
...
...
@@ -1500,12 +1500,12 @@ static void Main()
x = x / x;
}
catch (DivideByZeroException e)
if
(e.Message == null)
when
(e.Message == null)
{
Console.Write(""Catch1"");
}
catch (DivideByZeroException e)
if
(e.Message != null)
when
(e.Message != null)
{
Console.Write(""Catch2"" + e.Message.Length);
}
...
...
@@ -1615,7 +1615,7 @@ static void Main()
Console.Write(""Try"");
x = x / x;
}
catch
if
(new Func<bool>(() => str.Length == 2)())
catch
when
(new Func<bool>(() => str.Length == 2)())
{
Console.Write(""Catch"" + str);
}
...
...
@@ -1939,13 +1939,13 @@ static void M()
int a = 1;
try { }
catch (System.Exception) { }
catch
if
(a == 1) { }
catch
when
(a == 1) { }
}
}
"
;
CreateCompilationWithMscorlib
(
text
).
VerifyDiagnostics
(
// (9,9): warning CS1058: A previous catch clause already catches all exceptions. All non-exceptions thrown will be wrapped in a System.Runtime.CompilerServices.RuntimeWrappedException.
// catch
if
(a == 1) { }
// catch
when
(a == 1) { }
Diagnostic
(
ErrorCode
.
WRN_UnreachableGeneralCatch
,
"catch"
).
WithLocation
(
9
,
9
));
}
...
...
@@ -1959,8 +1959,8 @@ static void M()
{
int a = 1;
try { }
catch
if
(a == 2) { }
catch (System.Exception)
if
(a == 3) { }
catch
when
(a == 2) { }
catch (System.Exception)
when
(a == 3) { }
catch { }
}
}
...
...
Src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs
浏览文件 @
1ff04c56
...
...
@@ -4762,7 +4762,7 @@ .maxstack 3
}
/// Local names array (from PDB) may have fewer slots than method
/// signature (from metadata)
if
the trailing slots are unnamed.
/// signature (from metadata)
when
the trailing slots are unnamed.
/// </summary>
[
WorkItem
(
782270
,
"DevDiv"
)]
[
Fact
]
...
...
Src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs
浏览文件 @
1ff04c56
...
...
@@ -2611,7 +2611,7 @@ static void Main()
{
throw new System.Exception();
}
catch (System.Exception e)
if
(e.Message != null)
catch (System.Exception e)
when
(e.Message != null)
{
System.Console.WriteLine();
}
...
...
@@ -2636,7 +2636,7 @@ static void Main()
<entry il_offset=""0x1"" start_row=""7"" start_column=""9"" end_row=""7"" end_column=""10"" file_ref=""0"" />
<entry il_offset=""0x2"" start_row=""8"" start_column=""13"" end_row=""8"" end_column=""42"" file_ref=""0"" />
<entry il_offset=""0x8"" hidden=""true"" start_row=""16707566"" start_column=""0"" end_row=""16707566"" end_column=""0"" file_ref=""0"" />
<entry il_offset=""0x15"" start_row=""10"" start_column=""36"" end_row=""10"" end_column=""
58
"" file_ref=""0"" />
<entry il_offset=""0x15"" start_row=""10"" start_column=""36"" end_row=""10"" end_column=""
60
"" file_ref=""0"" />
<entry il_offset=""0x23"" hidden=""true"" start_row=""16707566"" start_column=""0"" end_row=""16707566"" end_column=""0"" file_ref=""0"" />
<entry il_offset=""0x24"" start_row=""11"" start_column=""9"" end_row=""11"" end_column=""10"" file_ref=""0"" />
<entry il_offset=""0x25"" start_row=""12"" start_column=""13"" end_row=""12"" end_column=""40"" file_ref=""0"" />
...
...
@@ -2653,8 +2653,7 @@ static void Main()
</scope>
</method>
</methods>
</symbols>
"
);
</symbols>"
);
}
[
Fact
]
...
...
@@ -2669,7 +2668,7 @@ static void Main()
{
throw new System.Exception();
}
catch
if
(F())
catch
when
(F())
{
System.Console.WriteLine();
}
...
...
@@ -2696,7 +2695,7 @@ private static bool F()
<entry il_offset=""0x1"" start_row=""7"" start_column=""9"" end_row=""7"" end_column=""10"" file_ref=""0"" />
<entry il_offset=""0x2"" start_row=""8"" start_column=""13"" end_row=""8"" end_column=""42"" file_ref=""0"" />
<entry il_offset=""0x8"" hidden=""true"" start_row=""16707566"" start_column=""0"" end_row=""16707566"" end_column=""0"" file_ref=""0"" />
<entry il_offset=""0x15"" start_row=""10"" start_column=""15"" end_row=""10"" end_column=""2
3
"" file_ref=""0"" />
<entry il_offset=""0x15"" start_row=""10"" start_column=""15"" end_row=""10"" end_column=""2
5
"" file_ref=""0"" />
<entry il_offset=""0x1f"" hidden=""true"" start_row=""16707566"" start_column=""0"" end_row=""16707566"" end_column=""0"" file_ref=""0"" />
<entry il_offset=""0x20"" start_row=""11"" start_column=""9"" end_row=""11"" end_column=""10"" file_ref=""0"" />
<entry il_offset=""0x21"" start_row=""12"" start_column=""13"" end_row=""12"" end_column=""40"" file_ref=""0"" />
...
...
@@ -2706,8 +2705,7 @@ private static bool F()
<locals />
</method>
</methods>
</symbols>
"
);
</symbols>"
);
}
[
WorkItem
(
778655
,
"DevDiv"
)]
...
...
Src/Compilers/CSharp/Test/Semantic/FlowAnalysis/FlowTests.cs
浏览文件 @
1ff04c56
...
...
@@ -2066,7 +2066,7 @@ static void Main()
try
{
}
catch (System.Exception e)
if
(e.Message == null)
catch (System.Exception e)
when
(e.Message == null)
{
}
}
...
...
@@ -2086,7 +2086,7 @@ static void Main()
try
{
}
catch (System.Exception e)
if
(F())
catch (System.Exception e)
when
(F())
{
}
}
...
...
@@ -2096,7 +2096,7 @@ static void Main()
"
;
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (9,33): warning CS0168: The variable 'e' is declared but never used
// catch (System.Exception e)
if
(true)
// catch (System.Exception e)
when
(true)
Diagnostic
(
ErrorCode
.
WRN_UnreferencedVar
,
"e"
).
WithArguments
(
"e"
).
WithLocation
(
9
,
33
));
}
...
...
@@ -2114,7 +2114,7 @@ static void Main()
try
{
}
catch (Exception e)
if
((f = e) != null)
catch (Exception e)
when
((f = e) != null)
{
Console.WriteLine(f);
}
...
...
@@ -2138,7 +2138,7 @@ static void Main()
try
{
}
catch (Exception e)
if
(f == e)
catch (Exception e)
when
(f == e)
{
}
}
...
...
@@ -2146,7 +2146,7 @@ static void Main()
"
;
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (12,33): error CS0165: Use of unassigned local variable 'f'
// catch (Exception e)
if
(f == e)
// catch (Exception e)
when
(f == e)
Diagnostic
(
ErrorCode
.
ERR_UseDefViolation
,
"f"
).
WithArguments
(
"f"
));
}
...
...
@@ -2164,10 +2164,10 @@ static void Main()
try
{
}
catch (Exception e)
if
((f = e) != null)
catch (Exception e)
when
((f = e) != null)
{
}
catch (Exception e)
if
(f == e)
catch (Exception e)
when
(f == e)
{
}
}
...
...
@@ -2176,7 +2176,7 @@ static void Main()
// TODO (tomat): f is always gonna be assigned in subsequent filter expressions.
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (15,33): error CS0165: Use of unassigned local variable 'f'
// catch (Exception e)
if
(f == e)
// catch (Exception e)
when
(f == e)
Diagnostic
(
ErrorCode
.
ERR_UseDefViolation
,
"f"
).
WithArguments
(
"f"
));
}
...
...
@@ -2194,7 +2194,7 @@ static void Main()
try
{
}
catch (Exception e)
if
((f = e) != null)
catch (Exception e)
when
((f = e) != null)
{
Console.WriteLine(f);
Console.WriteLine(g);
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
浏览文件 @
1ff04c56
...
...
@@ -931,7 +931,7 @@ async static Task M1()
try
{
}
catch
if
(await Task.Factory.StartNew(() => false))
catch
when
(await Task.Factory.StartNew(() => false))
{
}
finally
...
...
@@ -941,8 +941,8 @@ async static Task M1()
}"
;
CreateCompilationWithMscorlib45
(
source
).
VerifyDiagnostics
(
// (11,19): error CS7094: Cannot await in the filter expression of a catch clause
// catch
if
(await Task.Factory.StartNew(() => false))
Diagnostic
(
ErrorCode
.
ERR_BadAwaitInCatchFilter
,
"await Task.Factory.StartNew(() => false)"
).
WithLocation
(
11
,
19
)
// catch
when
(await Task.Factory.StartNew(() => false))
Diagnostic
(
ErrorCode
.
ERR_BadAwaitInCatchFilter
,
"await Task.Factory.StartNew(() => false)"
).
WithLocation
(
11
,
21
)
);
}
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs
浏览文件 @
1ff04c56
...
...
@@ -3184,7 +3184,7 @@ void M()
try
{
}
catch (Exception e)
if
(d) //-local: System.Exception
catch (Exception e)
when
(d) //-local: System.Exception
//-thisReference: C
//-fieldAccess: dynamic
//-unaryOperator: bool
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
浏览文件 @
1ff04c56
...
...
@@ -5143,16 +5143,16 @@ static void M()
{
int a = 1;
try { }
catch
if
(a == 1) { }
catch (Exception e)
if
(e.Message == null) { }
catch
when
(a == 1) { }
catch (Exception e)
when
(e.Message == null) { }
catch (A) { }
catch (B e)
if
(e.Message == null) { }
catch (B e)
when
(e.Message == null) { }
}
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (15,16): error CS0160: A previous catch clause already catches all exceptions of this or of a super type ('A')
// catch (B e)
if
(e.Message == null) { }
// catch (B e)
when
(e.Message == null) { }
Diagnostic(ErrorCode.ERR_UnreachableCatch, "B").WithArguments("A").WithLocation(15, 16));
}
...
...
@@ -5169,15 +5169,15 @@ class Program
static void M()
{
try { }
catch (A)
if
(true) { }
catch (A)
when
(true) { }
catch (B) { }
}
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (11,23): warning CS7095: Filter expression is a constant, consider removing the filter
// catch (A)
if
(true) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "true").WithLocation(11, 2
3
));
// catch (A)
when
(true) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "true").WithLocation(11, 2
5
));
}
[Fact]
...
...
@@ -5192,19 +5192,19 @@ class Program
static void M()
{
try { }
catch
if
(true) { }
catch
when
(true) { }
catch (A) { }
catch
if
(false) { }
catch
when
(false) { }
}
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (10,19): warning CS7095: Filter expression is a constant, consider removing the filter
// catch
if
(true) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "true").WithLocation(10,
19
),
// catch
when
(true) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "true").WithLocation(10,
21
),
// (12,19): warning CS7095: Filter expression is a constant, consider removing the filter
// catch
if
(false) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(12,
19
));
// catch
when
(false) { }
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(12,
21
));
}
[Fact]
...
...
@@ -5220,7 +5220,7 @@ class Program
static void M()
{
try { }
catch (A)
if
(false)
catch (A)
when
(false)
{
Console.WriteLine(1);
}
...
...
@@ -5229,9 +5229,10 @@ static void M()
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (11,23): warning CS7095: Filter expression is a constant, consider removing the filter
// catch (A) if (false)
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(11, 23));
// (11,25): warning CS7095: Filter expression is a constant, consider removing the filter
// catch (A) when (false)
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(11, 25)
);
}
[Fact]
...
...
@@ -5246,7 +5247,7 @@ static void M()
{
int x;
try { }
catch (Exception)
if
(false)
catch (Exception)
when
(false)
{
Console.WriteLine(x);
}
...
...
@@ -5258,12 +5259,13 @@ static void M()
// is to make conditional compilation easier. Such scenario doesn't apply to filters.
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (10,31): warning CS7095: Filter expression is a constant, consider removing the filter
// catch (Exception) if (false)
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(10, 31),
// (12,31): error CS0165: Use of unassigned local variable 'x'
// Console.WriteLine(x);
Diagnostic(ErrorCode.ERR_UseDefViolation, "x").WithArguments("x").WithLocation(12, 31));
// (10,33): warning CS7095: Filter expression is a constant, consider removing the filter
// catch (Exception) when (false)
Diagnostic(ErrorCode.WRN_FilterIsConstant, "false").WithLocation(10, 33),
// (12,31): error CS0165: Use of unassigned local variable 'x'
// Console.WriteLine(x);
Diagnostic(ErrorCode.ERR_UseDefViolation, "x").WithArguments("x").WithLocation(12, 31)
);
}
[Fact]
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
浏览文件 @
1ff04c56
...
...
@@ -25,7 +25,7 @@ static void Main()
try
{
}
catch (System.IO.IOException e)
if
(e.Message != null)
catch (System.IO.IOException e)
when
(e.Message != null)
{
}
}
...
...
Src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
1ff04c56
...
...
@@ -1689,7 +1689,7 @@ public static int Main()
catch {}
catch (S1) {}
catch (S) {}
catch
if
(false) {}
catch
when
(false) {}
if (retval == 0) Console.WriteLine(""PASS"");
else Console.WriteLine(""FAIL"");
return retval;
...
...
@@ -1721,7 +1721,7 @@ public static int Main()
try {
throw new S();
}
catch
if
(true) {}
catch
when
(true) {}
catch (S1) {}
catch (S) {}
if (retval == 0) Console.WriteLine(""PASS"");
...
...
@@ -4240,7 +4240,7 @@ public class C
{
public static int Main()
{
try { } catch
if
(true) {}
try { } catch
when
(true) {}
}
}
"
;
...
...
@@ -4249,9 +4249,10 @@ public static int Main()
tree
=
Parse
(
text
,
options
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
));
tree
.
GetDiagnostics
().
Verify
(
// (6,23): error CS8026: Feature 'exception filter' is not available in C# 5. Please use language version 6 or greater.
// try { } catch if (true) {}
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"if"
).
WithArguments
(
"exception filter"
,
"6"
));
// (6,23): error CS8026: Feature 'exception filter' is not available in C# 5. Please use language version 6 or greater.
// try { } catch when (true) {}
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"when"
).
WithArguments
(
"exception filter"
,
"6"
).
WithLocation
(
6
,
23
)
);
}
#
endregion
...
...
@@ -4678,7 +4679,7 @@ public void CSharp6Features()
void P(object o)
{
try {
} catch (Exception ex)
if
(ex.ToString() == null) { // exception filter
} catch (Exception ex)
when
(ex.ToString() == null) { // exception filter
}
var s = o?.ToString(); // null propagating operator
...
...
@@ -4687,30 +4688,31 @@ void P(object o)
SyntaxFactory
.
ParseSyntaxTree
(
source
,
options
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp6
)).
GetDiagnostics
().
Verify
();
SyntaxFactory
.
ParseSyntaxTree
(
source
,
options
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
)).
GetDiagnostics
().
Verify
(
// (3,20): error CS8026: Feature 'auto property initializer' is not available in C# 5. Please use language version 6 or greater.
// int L { get; } = 12; // auto property initializer
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"= 12"
).
WithArguments
(
"auto property initializer"
,
"6"
).
WithLocation
(
3
,
20
),
// (5,13): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// int M() => 12; // expression-bodied method
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> 12"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
5
,
13
),
// (7,11): error CS8026: Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater.
// int N => 12; // expression-bodied property
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> 12"
).
WithArguments
(
"expression-bodied property"
,
"6"
).
WithLocation
(
7
,
11
),
// (9,21): error CS8026: Feature 'expression-bodied indexer' is not available in C# 5. Please use language version 6 or greater.
// int this[int a] => a + 1; // expression-bodied indexer
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> a + 1"
).
WithArguments
(
"expression-bodied indexer"
,
"6"
).
WithLocation
(
9
,
21
),
// (11,48): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// public static int operator +(Foo a, Foo b) => null; // expression-bodied operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> null"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
11
,
48
),
// (13,49): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// public static explicit operator bool(Foo a) => false; // expression-bodied conversion operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> false"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
13
,
49
),
// (18,32): error CS8026: Feature 'exception filter' is not available in C# 5. Please use language version 6 or greater.
// } catch (Exception ex) if (ex.ToString() == null) { // exception filter
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"if"
).
WithArguments
(
"exception filter"
,
"6"
).
WithLocation
(
18
,
32
),
// (21,17): error CS8026: Feature 'null propagating operator' is not available in C# 5. Please use language version 6 or greater.
// var s = o?.ToString(); // null propagating operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"o?.ToString()"
).
WithArguments
(
"null propagating operator"
,
"6"
).
WithLocation
(
21
,
17
));
// (3,20): error CS8026: Feature 'auto property initializer' is not available in C# 5. Please use language version 6 or greater.
// int L { get; } = 12; // auto property initializer
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"= 12"
).
WithArguments
(
"auto property initializer"
,
"6"
).
WithLocation
(
3
,
20
),
// (5,13): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// int M() => 12; // expression-bodied method
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> 12"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
5
,
13
),
// (7,11): error CS8026: Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater.
// int N => 12; // expression-bodied property
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> 12"
).
WithArguments
(
"expression-bodied property"
,
"6"
).
WithLocation
(
7
,
11
),
// (9,21): error CS8026: Feature 'expression-bodied indexer' is not available in C# 5. Please use language version 6 or greater.
// int this[int a] => a + 1; // expression-bodied indexer
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> a + 1"
).
WithArguments
(
"expression-bodied indexer"
,
"6"
).
WithLocation
(
9
,
21
),
// (11,48): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// public static int operator +(Foo a, Foo b) => null; // expression-bodied operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> null"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
11
,
48
),
// (13,49): error CS8026: Feature 'expression-bodied method' is not available in C# 5. Please use language version 6 or greater.
// public static explicit operator bool(Foo a) => false; // expression-bodied conversion operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"=> false"
).
WithArguments
(
"expression-bodied method"
,
"6"
).
WithLocation
(
13
,
49
),
// (18,32): error CS8026: Feature 'exception filter' is not available in C# 5. Please use language version 6 or greater.
// } catch (Exception ex) when (ex.ToString() == null) { // exception filter
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"when"
).
WithArguments
(
"exception filter"
,
"6"
).
WithLocation
(
18
,
32
),
// (21,17): error CS8026: Feature 'null propagating operator' is not available in C# 5. Please use language version 6 or greater.
// var s = o?.ToString(); // null propagating operator
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion5
,
"o?.ToString()"
).
WithArguments
(
"null propagating operator"
,
"6"
).
WithLocation
(
21
,
17
)
);
}
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录