Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
af35b152
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,发现更多精彩内容 >>
提交
af35b152
编写于
2月 24, 2016
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix NRE in "Literal.Text" when the constant value is null.
上级
16faf273
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
2 deletion
+69
-2
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
...Sharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
+38
-0
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
...ore/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
+29
-0
src/Compilers/Core/Portable/Compilation/Expression.cs
src/Compilers/Core/Portable/Compilation/Expression.cs
+1
-1
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
+1
-1
未找到文件。
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
浏览文件 @
af35b152
...
...
@@ -1560,5 +1560,43 @@ public void M0(C p)
Diagnostic
(
ConditionalAccessOperationTestAnalyzer
.
ConditionalAccessOperationDescriptor
.
Id
,
"Field1?.M0(null)"
).
WithLocation
(
32
,
9
),
Diagnostic
(
ConditionalAccessOperationTestAnalyzer
.
ConditionalAccessInstanceOperationDescriptor
.
Id
,
"Field1"
).
WithLocation
(
32
,
9
));
}
[
WorkItem
(
9116
,
"https://github.com/dotnet/roslyn/issues/9116"
)]
[
Fact
]
public
void
LiteralCSharp
()
{
const
string
source
=
@"
public class A
{
public void M()
{
object a = null;
}
}
struct S
{
void M(
int i = 1,
string str = ""hello"",
object o = null,
S s = default(S))
{
M();
}
}
"
;
CreateCompilationWithMscorlib45
(
source
)
.
VerifyDiagnostics
(
Diagnostic
(
ErrorCode
.
WRN_UnreferencedVarAssg
,
"a"
).
WithArguments
(
"a"
).
WithLocation
(
6
,
16
))
.
VerifyAnalyzerDiagnostics
(
new
DiagnosticAnalyzer
[]
{
new
LiteralTestAnalyzer
()
},
null
,
null
,
false
,
Diagnostic
(
"Literal"
,
"null"
).
WithArguments
(
"null"
).
WithLocation
(
6
,
20
),
Diagnostic
(
"Literal"
,
"1"
).
WithArguments
(
"1"
).
WithLocation
(
13
,
17
),
Diagnostic
(
"Literal"
,
@"""hello"""
).
WithArguments
(
@"""hello"""
).
WithLocation
(
14
,
22
),
Diagnostic
(
"Literal"
,
"null"
).
WithArguments
(
"null"
).
WithLocation
(
15
,
20
),
Diagnostic
(
"Literal"
,
"M()"
).
WithArguments
(
"1"
).
WithLocation
(
18
,
9
),
Diagnostic
(
"Literal"
,
"M()"
).
WithArguments
(
@"""hello"""
).
WithLocation
(
18
,
9
),
Diagnostic
(
"Literal"
,
"M()"
).
WithArguments
(
"null"
).
WithLocation
(
18
,
9
),
Diagnostic
(
"Literal"
,
"M()"
).
WithArguments
(
"null"
).
WithLocation
(
18
,
9
));
}
}
}
\ No newline at end of file
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
af35b152
...
...
@@ -1773,4 +1773,33 @@ public sealed override void Initialize(AnalysisContext context)
OperationKind
.
LoopStatement
);
}
}
public
class
LiteralTestAnalyzer
:
DiagnosticAnalyzer
{
private
const
string
ReliabilityCategory
=
"Reliability"
;
public
static
readonly
DiagnosticDescriptor
LiteralDescriptor
=
new
DiagnosticDescriptor
(
"Literal"
,
"A literal is found"
,
"A literal of value {0} is found"
,
ReliabilityCategory
,
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
sealed
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
{
get
{
return
ImmutableArray
.
Create
(
LiteralDescriptor
);
}
}
public
sealed
override
void
Initialize
(
AnalysisContext
context
)
{
context
.
RegisterOperationAction
(
(
operationContext
)
=>
{
var
literal
=
(
ILiteralExpression
)
operationContext
.
Operation
;
operationContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
LiteralDescriptor
,
literal
.
Syntax
.
GetLocation
(),
literal
.
Text
));
},
OperationKind
.
LiteralExpression
);
}
}
}
\ No newline at end of file
src/Compilers/Core/Portable/Compilation/Expression.cs
浏览文件 @
af35b152
...
...
@@ -308,7 +308,7 @@ public Literal(ConstantValue value, ITypeSymbol resultType, SyntaxNode syntax)
this
.
Syntax
=
syntax
;
}
public
string
Text
=>
_value
.
Value
.
ToString
();
public
string
Text
=>
_value
.
GetValueToDisplay
();
public
ITypeSymbol
Type
{
get
;
}
...
...
src/Compilers/Core/Portable/Compilation/OperationWalker.cs
浏览文件 @
af35b152
...
...
@@ -193,7 +193,7 @@ public override void VisitEndStatement(IEndStatement operation)
public
override
void
VisitInvocationExpression
(
IInvocationExpression
operation
)
{
Visit
(
operation
.
Instance
);
VisitArray
(
operation
.
ArgumentsIn
Source
Order
);
VisitArray
(
operation
.
ArgumentsIn
Parameter
Order
);
}
public
override
void
VisitArgument
(
IArgument
operation
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录