Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3e855782
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,发现更多精彩内容 >>
提交
3e855782
编写于
2月 22, 2016
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix crash in `EventAssignmentExpression.EventInstance` in VB
Which is caused by invalid code.
上级
993b6248
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
2 deletion
+105
-2
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
...ore/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
+25
-1
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
+1
-1
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
...Basic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
+79
-0
未找到文件。
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
3e855782
...
...
@@ -935,6 +935,14 @@ public class MemberReferenceAnalyzer : DiagnosticAnalyzer
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
static
readonly
DiagnosticDescriptor
InvalidEventDescriptor
=
new
DiagnosticDescriptor
(
"InvalidEvent"
,
"Invalid Event"
,
"A EventAssignmentExpression with invalid event found."
,
"Testing"
,
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
static
readonly
DiagnosticDescriptor
HandlerAddedDescriptor
=
new
DiagnosticDescriptor
(
"HandlerAdded"
,
"Handler Added"
,
...
...
@@ -975,7 +983,14 @@ public class MemberReferenceAnalyzer : DiagnosticAnalyzer
DiagnosticSeverity
.
Warning
,
isEnabledByDefault
:
true
);
public
sealed
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
EventReferenceDescriptor
,
HandlerAddedDescriptor
,
HandlerRemovedDescriptor
,
PropertyReferenceDescriptor
,
FieldReferenceDescriptor
,
MethodBindingDescriptor
);
public
sealed
override
ImmutableArray
<
DiagnosticDescriptor
>
SupportedDiagnostics
=>
ImmutableArray
.
Create
(
EventReferenceDescriptor
,
HandlerAddedDescriptor
,
HandlerRemovedDescriptor
,
PropertyReferenceDescriptor
,
FieldReferenceDescriptor
,
MethodBindingDescriptor
,
InvalidEventDescriptor
);
public
sealed
override
void
Initialize
(
AnalysisContext
context
)
{
...
...
@@ -991,6 +1006,15 @@ public sealed override void Initialize(AnalysisContext context)
{
IEventAssignmentExpression
eventAssignment
=
(
IEventAssignmentExpression
)
operationContext
.
Operation
;
operationContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
eventAssignment
.
Adds
?
HandlerAddedDescriptor
:
HandlerRemovedDescriptor
,
operationContext
.
Operation
.
Syntax
.
GetLocation
()));
if
(
eventAssignment
.
Event
==
null
)
{
if
(
eventAssignment
.
EventInstance
==
null
&&
eventAssignment
.
IsInvalid
)
{
// report inside after checking for null to make sure it does't crash.
operationContext
.
ReportDiagnostic
(
Diagnostic
.
Create
(
InvalidEventDescriptor
,
eventAssignment
.
Syntax
.
GetLocation
()));
}
}
},
OperationKind
.
EventAssignmentExpression
);
...
...
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
浏览文件 @
3e855782
...
...
@@ -1545,7 +1545,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Public
ReadOnly
Property
EventInstance
As
IOperation
Implements
IEventAssignmentExpression
.
EventInstance
Get
If
[
Event
]
.
IsStatic
Then
If
[
Event
]
Is
Nothing
OrElse
[
Event
]
.
IsStatic
Then
Return
Nothing
End
If
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
浏览文件 @
3e855782
...
...
@@ -1724,5 +1724,84 @@ End Module
Diagnostic
(
ForLoopConditionCrashVBTestAnalyzer
.
ForLoopConditionCrashDescriptor
.
Id
,
"Boo"
).
WithLocation
(
41
,
24
),
Diagnostic
(
ForLoopConditionCrashVBTestAnalyzer
.
ForLoopConditionCrashDescriptor
.
Id
,
"10"
).
WithLocation
(
19
,
40
))
End
Sub
<
WorkItem
(
9012
,
"https://github.com/dotnet/roslyn/issues/9012"
)
>
<
Fact
>
Public
Sub
InvalidEventInstanceVisualBasic
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
Imports
System
Imports
System.Collections.Generic
Module
Program
Sub
Main
(
args
As
String
())
AddHandler
Function
(
ByVal
x
)
x
End
Sub
End
Module
Class
TestClass
Event
TestEvent
As
Action
Shared
Sub
Test
(
receiver
As
TestClass
)
AddHandler
receiver
?
.
TestEvent
,
AddressOf
Main
End
Sub
Shared
Sub
Main
()
End
Sub
End
Class
Module
Module1
Sub
Main
()
Dim
x
=
{
Iterator
sub
()
yield
,
new
object
}
Dim
y
=
{
Iterator
sub
()
yield
1
,
Iterator
sub
()
yield
,
new
object
}
Dim
z
=
{
Sub
()
AddHandler
,
New
Object
}
g0
(
Iterator
sub
()
Yield
)
g1
(
Iterator
Sub
()
Yield
,
5
)
End
Sub
Sub
g0
(
ByVal
x
As
Func
(
Of
IEnumerator
))
End
Sub
Sub
g1
(
ByVal
x
As
Func
(
Of
IEnumerator
),
ByVal
y
As
Integer
)
End
Sub
Iterator
Function
f
()
As
IEnumerator
Yield
End
Function
End
Module
]]
>
</
file
>
</
compilation
>
Dim
comp
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
(
Diagnostic
(
ERRID
.
ERR_ExpectedComma
,
""
).
WithLocation
(
6
,
39
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
6
,
39
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
24
,
38
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
25
,
62
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
26
,
34
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
27
,
32
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
28
,
32
),
Diagnostic
(
ERRID
.
ERR_ExpectedExpression
,
""
).
WithLocation
(
37
,
14
),
Diagnostic
(
ERRID
.
ERR_TooFewGenericArguments1
,
"IEnumerator"
).
WithArguments
(
"System.Collections.Generic.IEnumerator(Of Out T)"
).
WithLocation
(
31
,
31
),
Diagnostic
(
ERRID
.
ERR_TooFewGenericArguments1
,
"IEnumerator"
).
WithArguments
(
"System.Collections.Generic.IEnumerator(Of Out T)"
).
WithLocation
(
33
,
31
),
Diagnostic
(
ERRID
.
ERR_TooFewGenericArguments1
,
"IEnumerator"
).
WithArguments
(
"System.Collections.Generic.IEnumerator(Of Out T)"
).
WithLocation
(
36
,
30
),
Diagnostic
(
ERRID
.
ERR_AddOrRemoveHandlerEvent
,
"receiver?.TestEvent"
).
WithLocation
(
15
,
20
),
Diagnostic
(
ERRID
.
ERR_AddOrRemoveHandlerEvent
,
"Function(ByVal x) x"
).
WithLocation
(
6
,
20
),
Diagnostic
(
ERRID
.
ERR_BadIteratorReturn
,
"sub"
).
WithLocation
(
24
,
27
),
Diagnostic
(
ERRID
.
ERR_BadIteratorReturn
,
"sub"
).
WithLocation
(
25
,
27
),
Diagnostic
(
ERRID
.
ERR_BadIteratorReturn
,
"sub"
).
WithLocation
(
25
,
51
),
Diagnostic
(
ERRID
.
ERR_BadIteratorReturn
,
"sub"
).
WithLocation
(
27
,
21
),
Diagnostic
(
ERRID
.
ERR_BadIteratorReturn
,
"Sub"
).
WithLocation
(
28
,
21
),
Diagnostic
(
ERRID
.
HDN_UnusedImportStatement
,
"Imports System.Collections.Generic"
).
WithLocation
(
2
,
1
))
comp
.
VerifyAnalyzerDiagnostics
({
New
MemberReferenceAnalyzer
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
MemberReferenceAnalyzer
.
HandlerAddedDescriptor
.
Id
,
"AddHandler, New Object"
).
WithLocation
(
26
,
24
),
Diagnostic
(
MemberReferenceAnalyzer
.
InvalidEventDescriptor
.
Id
,
"AddHandler, New Object"
).
WithLocation
(
26
,
24
),
Diagnostic
(
MemberReferenceAnalyzer
.
HandlerAddedDescriptor
.
Id
,
"AddHandler receiver?.TestEvent, AddressOf Main"
).
WithLocation
(
15
,
9
),
Diagnostic
(
MemberReferenceAnalyzer
.
InvalidEventDescriptor
.
Id
,
"AddHandler receiver?.TestEvent, AddressOf Main"
).
WithLocation
(
15
,
9
),
Diagnostic
(
MemberReferenceAnalyzer
.
HandlerAddedDescriptor
.
Id
,
"AddHandler Function(ByVal x) x"
).
WithLocation
(
6
,
9
),
Diagnostic
(
MemberReferenceAnalyzer
.
InvalidEventDescriptor
.
Id
,
"AddHandler Function(ByVal x) x"
).
WithLocation
(
6
,
9
))
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录