Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d0a377e6
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,发现更多精彩内容 >>
提交
d0a377e6
编写于
12月 23, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
12月 23, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16087 from CyrusNajmabadi/parserDiagnostics
Move diagnostic from parser to later phase.
上级
07dc0b23
8b561389
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
28 deletion
+25
-28
src/Compilers/CSharp/Portable/Binder/Imports.cs
src/Compilers/CSharp/Portable/Binder/Imports.cs
+5
-0
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+5
-22
src/Compilers/CSharp/Test/Syntax/LexicalAndXml/PreprocessorTests.cs
...ers/CSharp/Test/Syntax/LexicalAndXml/PreprocessorTests.cs
+8
-5
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+7
-1
未找到文件。
src/Compilers/CSharp/Portable/Binder/Imports.cs
浏览文件 @
d0a377e6
...
...
@@ -138,6 +138,11 @@ internal string GetDebuggerDisplay()
if
(
usingDirective
.
Alias
!=
null
)
{
if
(
usingDirective
.
Alias
.
Name
.
Identifier
.
ContextualKind
()
==
SyntaxKind
.
GlobalKeyword
)
{
diagnostics
.
Add
(
ErrorCode
.
WRN_GlobalAliasDefn
,
usingDirective
.
Alias
.
Name
.
Location
);
}
if
(
usingDirective
.
StaticKeyword
!=
default
(
SyntaxToken
))
{
diagnostics
.
Add
(
ErrorCode
.
ERR_NoAliasHere
,
usingDirective
.
Alias
.
Name
.
Location
);
...
...
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
d0a377e6
...
...
@@ -59,11 +59,6 @@ private static bool IsName(CSharpSyntaxNode node, SyntaxKind kind)
}
}
private
static
bool
IsNameGlobal
(
CSharpSyntaxNode
node
)
{
return
IsName
(
node
,
SyntaxKind
.
GlobalKeyword
);
}
private
static
bool
IsNameGet
(
CSharpSyntaxNode
node
)
{
return
IsName
(
node
,
SyntaxKind
.
GetKeyword
);
...
...
@@ -865,20 +860,12 @@ private ExternAliasDirectiveSyntax ParseExternAliasDirective()
return
_syntaxFactory
.
ExternAliasDirective
(
externToken
,
aliasToken
,
name
,
semicolon
);
}
private
NameEqualsSyntax
ParseNameEquals
(
bool
warnOnGlobal
=
false
)
private
NameEqualsSyntax
ParseNameEquals
()
{
Debug
.
Assert
(
this
.
IsNamedAssignment
());
var
id
=
this
.
ParseIdentifierToken
();
var
equals
=
this
.
EatToken
(
SyntaxKind
.
EqualsToken
);
// Warn on "using global = X".
if
(
warnOnGlobal
&&
IsNameGlobal
(
id
))
{
id
=
this
.
AddError
(
id
,
ErrorCode
.
WRN_GlobalAliasDefn
);
}
return
_syntaxFactory
.
NameEquals
(
_syntaxFactory
.
IdentifierName
(
id
),
equals
);
return
_syntaxFactory
.
NameEquals
(
_syntaxFactory
.
IdentifierName
(
this
.
ParseIdentifierToken
()),
this
.
EatToken
(
SyntaxKind
.
EqualsToken
));
}
private
UsingDirectiveSyntax
ParseUsingDirective
()
...
...
@@ -898,11 +885,7 @@ private UsingDirectiveSyntax ParseUsingDirective()
staticToken
=
this
.
EatToken
(
SyntaxKind
.
StaticKeyword
);
}
NameEqualsSyntax
alias
=
null
;
if
(
this
.
IsNamedAssignment
())
{
alias
=
ParseNameEquals
(
warnOnGlobal
:
true
);
}
var
alias
=
this
.
IsNamedAssignment
()
?
ParseNameEquals
()
:
null
;
NameSyntax
name
;
SyntaxToken
semicolon
;
...
...
src/Compilers/CSharp/Test/Syntax/LexicalAndXml/PreprocessorTests.cs
浏览文件 @
d0a377e6
...
...
@@ -3326,18 +3326,21 @@ public void TestPragmaWarningDisableWithMultipleCodes()
[
Trait
(
"Feature"
,
"Directives"
)]
public
void
TestRegressPragmaWarningDisableWithWarningCode
()
{
var
text
=
@"#pragma warning disable 440
using global = A; // CS0440
var
text
=
@"
class A
{
static void Main() { }
static void Main(bool b)
{
#pragma warning disable 642
if (b);{}
}
}
"
;
// verify that error still appears in GetDiagnostics
var
tree
=
SyntaxFactory
.
ParseSyntaxTree
(
text
);
var
diagnostic
=
tree
.
GetDiagnostics
().
Single
();
Assert
.
Equal
(
DiagnosticSeverity
.
Warning
,
diagnostic
.
Severity
);
Assert
.
Equal
(
440
,
diagnostic
.
Code
);
Assert
.
Equal
(
642
,
diagnostic
.
Code
);
// verify pragma information
var
node
=
tree
.
GetCompilationUnitRoot
();
...
...
@@ -3346,7 +3349,7 @@ class A
PragmaKind
=
SyntaxKind
.
PragmaWarningDirectiveTrivia
,
WarningOrChecksumKind
=
SyntaxKind
.
WarningKeyword
,
DisableOrRestoreKind
=
SyntaxKind
.
DisableKeyword
,
WarningList
=
new
[]
{
"
440
"
}
WarningList
=
new
[]
{
"
642
"
}
});
// verify that GetParseDiagnostics filters disabled warning
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
d0a377e6
...
...
@@ -4543,7 +4543,13 @@ static void Main()
}
"
;
ParseAndValidate
(
test
,
Diagnostic
(
ErrorCode
.
WRN_GlobalAliasDefn
,
"global"
));
CreateCompilationWithMscorlib
(
test
).
VerifyDiagnostics
(
// (2,7): warning CS0440: Defining an alias named 'global' is ill-advised since 'global::' always references the global namespace and not an alias
// using global = MyClass; // CS0440
Diagnostic
(
ErrorCode
.
WRN_GlobalAliasDefn
,
"global"
).
WithLocation
(
2
,
7
),
// (2,1): hidden CS8019: Unnecessary using directive.
// using global = MyClass; // CS0440
Diagnostic
(
ErrorCode
.
HDN_UnusedUsingDirective
,
"using global = MyClass;"
).
WithLocation
(
2
,
1
));
}
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录