Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
09c7d0bd
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,发现更多精彩内容 >>
提交
09c7d0bd
编写于
1月 06, 2015
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure that SemanicModel doesn’t dereference null binder.
***NO_CI*** (changeset 1392909)
上级
d66cab23
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
90 addition
and
2 deletion
+90
-2
Src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
...pilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
+30
-2
Src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs
Src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs
+60
-0
未找到文件。
Src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
浏览文件 @
09c7d0bd
...
...
@@ -2757,7 +2757,21 @@ public ILocalSymbol GetDeclaredSymbol(ForEachStatementSyntax forEachStatement, C
using
(
Logger
.
LogBlock
(
FunctionId
.
CSharp_SemanticModel_GetDeclaredSymbol
,
message
:
this
.
SyntaxTree
.
FilePath
,
cancellationToken
:
cancellationToken
))
{
Binder
enclosingBinder
=
this
.
GetEnclosingBinder
(
GetAdjustedNodePosition
(
forEachStatement
));
Binder
foreachBinder
=
enclosingBinder
.
GetBinder
(
forEachStatement
).
WithAdditionalFlags
(
BinderFlags
.
SemanticModel
);
if
(
enclosingBinder
==
null
)
{
return
null
;
}
Binder
foreachBinder
=
enclosingBinder
.
GetBinder
(
forEachStatement
);
// Binder.GetBinder can fail in presence of syntax errors.
if
(
foreachBinder
==
null
)
{
return
null
;
}
foreachBinder
=
foreachBinder
.
WithAdditionalFlags
(
BinderFlags
.
SemanticModel
);
LocalSymbol
local
=
foreachBinder
.
Locals
.
FirstOrDefault
();
return
((
object
)
local
!=
null
&&
local
.
DeclarationKind
==
LocalDeclarationKind
.
ForEachIterationVariable
)
?
local
...
...
@@ -2777,7 +2791,21 @@ public ILocalSymbol GetDeclaredSymbol(CatchDeclarationSyntax catchDeclaration, C
CSharpSyntaxNode
catchClause
=
catchDeclaration
.
Parent
;
//Syntax->Binder map is keyed on clause, not decl
Debug
.
Assert
(
catchClause
.
Kind
()
==
SyntaxKind
.
CatchClause
);
Binder
enclosingBinder
=
this
.
GetEnclosingBinder
(
GetAdjustedNodePosition
(
catchClause
));
Binder
catchBinder
=
enclosingBinder
.
GetBinder
(
catchClause
).
WithAdditionalFlags
(
BinderFlags
.
SemanticModel
);
if
(
enclosingBinder
==
null
)
{
return
null
;
}
Binder
catchBinder
=
enclosingBinder
.
GetBinder
(
catchClause
);
// Binder.GetBinder can fail in presence of syntax errors.
if
(
catchBinder
==
null
)
{
return
null
;
}
catchBinder
=
catchBinder
.
WithAdditionalFlags
(
BinderFlags
.
SemanticModel
);
LocalSymbol
local
=
catchBinder
.
Locals
.
FirstOrDefault
();
return
((
object
)
local
!=
null
&&
local
.
DeclarationKind
==
LocalDeclarationKind
.
CatchVariable
)
?
local
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs
浏览文件 @
09c7d0bd
...
...
@@ -2907,5 +2907,65 @@ private static BoundForEachStatement GetBoundForEachStatement(string text, param
return
boundNode
;
}
[
WorkItem
(
1100741
,
"DevDiv"
)]
[
Fact
]
public
void
Bug1100741
()
{
var
source
=
@"
namespace ImmutableObjectGraph
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IdentityFieldType = System.UInt32;
public static class RecursiveTypeExtensions
{
/// <summary>Gets the recursive parent of the specified value, or <c>null</c> if none could be found.</summary>
internal ParentedRecursiveType<<#= templateType.RecursiveParent.TypeName #>, <#= templateType.RecursiveTypeFromFamily.TypeName #>> GetParentedNode(<#= templateType.RequiredIdentityField.TypeName #> identity) {
if (this.Identity == identity) {
return new ParentedRecursiveType<<#= templateType.RecursiveParent.TypeName #>, <#= templateType.RecursiveTypeFromFamily.TypeName #>>(this, null);
}
if (this.LookupTable != null) {
System.Collections.Generic.KeyValuePair<<#= templateType.RecursiveType.TypeName #>, <#= templateType.RequiredIdentityField.TypeName #>> lookupValue;
if (this.LookupTable.TryGetValue(identity, out lookupValue)) {
var parentIdentity = lookupValue.Value;
return new ParentedRecursiveType<<#= templateType.RecursiveParent.TypeName #>, <#= templateType.RecursiveTypeFromFamily.TypeName #>>(this.LookupTable[identity].Key, (<#= templateType.RecursiveParent.TypeName #>)this.Find(parentIdentity));
}
} else {
// No lookup table means we have to aggressively search each child.
foreach (var child in this.Children) {
if (child.Identity.Equals(identity)) {
return new ParentedRecursiveType<<#= templateType.RecursiveParent.TypeName #>, <#= templateType.RecursiveTypeFromFamily.TypeName #>>(child, this);
}
var recursiveChild = child as <#= templateType.RecursiveParent.TypeName #>;
if (recursiveChild != null) {
var childResult = recursiveChild.GetParentedNode(identity);
if (childResult.Value != null) {
return childResult;
}
}
}
}
return default(ParentedRecursiveType<<#= templateType.RecursiveParent.TypeName #>, <#= templateType.RecursiveTypeFromFamily.TypeName #>>);
}
}
}
"
;
var
compilation
=
CreateCompilationWithMscorlib
(
source
);
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
node
=
tree
.
GetRoot
().
DescendantNodes
().
Where
(
n
=>
n
.
Kind
()
==
SyntaxKind
.
ForEachStatement
).
OfType
<
ForEachStatementSyntax
>().
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
Assert
.
Null
(
model
.
GetDeclaredSymbol
(
node
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录