Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d0fb7a83
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,发现更多精彩内容 >>
提交
d0fb7a83
编写于
1月 03, 2017
作者:
C
CyrusNajmabadi
提交者:
GitHub
1月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16143 from CyrusNajmabadi/parserDiagnostics16
Allow parsing any types in catch clauses in the parser.
上级
3ae77849
e6bb9097
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
30 deletion
+39
-30
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+3
-27
src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
...Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
+26
-0
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+10
-3
未找到文件。
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
d0fb7a83
...
...
@@ -7543,16 +7543,17 @@ private CatchClauseSyntax ParseCatchClause()
if
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
OpenParenToken
)
{
var
openParen
=
this
.
EatToken
();
_termState
|=
TerminatorState
.
IsEndOfCatchClause
;
var
type
=
this
.
Parse
Class
Type
();
var
type
=
this
.
ParseType
();
SyntaxToken
name
=
null
;
if
(
this
.
IsTrueIdentifier
())
{
name
=
this
.
ParseIdentifierToken
();
}
_termState
=
saveTerm
;
var
closeParen
=
this
.
EatToken
(
SyntaxKind
.
CloseParenToken
);
decl
=
_syntaxFactory
.
CatchDeclaration
(
openParen
,
type
,
name
,
closeParen
);
}
...
...
@@ -7613,31 +7614,6 @@ private bool IsEndOfCatchBlock()
||
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
FinallyKeyword
;
}
private
TypeSyntax
ParseClassType
()
{
var
type
=
this
.
ParseType
();
switch
(
type
.
Kind
)
{
case
SyntaxKind
.
PredefinedType
:
var
kt
=
((
PredefinedTypeSyntax
)
type
).
Keyword
.
Kind
;
if
(
kt
!=
SyntaxKind
.
ObjectKeyword
&&
kt
!=
SyntaxKind
.
StringKeyword
)
{
goto
default
;
}
break
;
default
:
if
(!
SyntaxFacts
.
IsName
(
type
.
Kind
))
{
type
=
this
.
AddError
(
type
,
ErrorCode
.
ERR_ClassTypeExpected
);
}
break
;
}
return
type
;
}
private
StatementSyntax
ParseCheckedStatement
()
{
Debug
.
Assert
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
CheckedKeyword
||
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
UncheckedKeyword
);
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/TryCatchTests.cs
浏览文件 @
d0fb7a83
...
...
@@ -46,6 +46,32 @@ static void Main()
Assert
.
Equal
(
"string.operator !=(string, string)"
,
filterExprInfo
.
Symbol
.
ToDisplayString
());
}
[
Fact
]
public
void
CatchClauseValueType
()
{
var
source
=
@"
class C
{
static void Main()
{
try
{
}
catch (int e)
{
}
}
}
"
;
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
// (9,16): error CS0155: The type caught or thrown must be derived from System.Exception
// catch (int e)
Diagnostic
(
ErrorCode
.
ERR_BadExceptionType
,
"int"
).
WithLocation
(
9
,
16
),
// (9,20): warning CS0168: The variable 'e' is declared but never used
// catch (int e)
Diagnostic
(
ErrorCode
.
WRN_UnreferencedVar
,
"e"
).
WithArguments
(
"e"
).
WithLocation
(
9
,
20
));
}
[
ConditionalFact
(
typeof
(
x86
))]
[
WorkItem
(
7030
,
"https://github.com/dotnet/roslyn/issues/7030"
)]
public
void
Issue7030
()
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
d0fb7a83
...
...
@@ -1647,9 +1647,16 @@ public static void Main()
}
"
;
ParseAndValidate
(
test
,
Diagnostic
(
ErrorCode
.
ERR_ClassTypeExpected
,
"int"
),
Diagnostic
(
ErrorCode
.
ERR_ClassTypeExpected
,
"byte"
));
CreateCompilationWithMscorlib
(
test
).
VerifyDiagnostics
(
// (10,15): error CS0155: The type caught or thrown must be derived from System.Exception
// catch(int)
Diagnostic
(
ErrorCode
.
ERR_BadExceptionType
,
"int"
).
WithLocation
(
10
,
15
),
// (13,15): error CS0155: The type caught or thrown must be derived from System.Exception
// catch(byte)
Diagnostic
(
ErrorCode
.
ERR_BadExceptionType
,
"byte"
).
WithLocation
(
13
,
15
),
// (2,1): hidden CS8019: Unnecessary using directive.
// using System;
Diagnostic
(
ErrorCode
.
HDN_UnusedUsingDirective
,
"using System;"
).
WithLocation
(
2
,
1
));
}
[
WorkItem
(
863382
,
"DevDiv/Personal"
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录