Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fce57c59
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,发现更多精彩内容 >>
提交
fce57c59
编写于
3月 12, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix crash when trying to get speculative info on too small an expression.
上级
5f014b56
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
6 deletion
+58
-6
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs
...lineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs
+55
-3
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
...eDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
+3
-3
未找到文件。
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationCodeFixProvider.cs
浏览文件 @
fce57c59
...
...
@@ -229,9 +229,31 @@ private static IEnumerable<SyntaxTrivia> MassageTrivia(IEnumerable<SyntaxTrivia>
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
previousSymbol
=
semanticModel
.
GetSymbolInfo
(
invocationOrCreation
).
Symbol
;
var
updatedInvocationOrCreation
=
invocationOrCreation
.
ReplaceNode
(
identifier
,
declarationExpression
);
var
updatedSymbolInfo
=
semanticModel
.
GetSpeculativeSymbolInfo
(
invocationOrCreation
.
SpanStart
,
updatedInvocationOrCreation
,
SpeculativeBindingOption
.
BindAsExpression
);
// Now, create a speculative model in which we make the change. Make sure
// we still point to the same symbol afterwards.
var
topmostContainer
=
GetTopmostContainer
(
invocationOrCreation
);
if
(
topmostContainer
==
null
)
{
// Couldn't figure out what we were contained in. Have to assume that semantics
// Are changing.
return
true
;
}
var
annotation
=
new
SyntaxAnnotation
();
var
updatedTopmostContainer
=
topmostContainer
.
ReplaceNode
(
invocationOrCreation
,
invocationOrCreation
.
ReplaceNode
(
identifier
,
declarationExpression
)
.
WithAdditionalAnnotations
(
annotation
));
if
(!
TryGetSpeculativeSemanticModel
(
semanticModel
,
topmostContainer
.
SpanStart
,
updatedTopmostContainer
,
out
var
speculativeModel
))
{
// Couldn't figure out the new semantics. Assume semantics changed.
return
true
;
}
var
updatedInvocationOrCreation
=
updatedTopmostContainer
.
GetAnnotatedNodes
(
annotation
).
Single
();
var
updatedSymbolInfo
=
speculativeModel
.
GetSymbolInfo
(
updatedInvocationOrCreation
);
if
(!
SymbolEquivalenceComparer
.
Instance
.
Equals
(
previousSymbol
,
updatedSymbolInfo
.
Symbol
))
{
...
...
@@ -243,6 +265,36 @@ private static IEnumerable<SyntaxTrivia> MassageTrivia(IEnumerable<SyntaxTrivia>
return
false
;
}
private
SyntaxNode
GetTopmostContainer
(
ExpressionSyntax
expression
)
{
return
expression
.
GetAncestorsOrThis
(
a
=>
a
is
StatementSyntax
||
a
is
EqualsValueClauseSyntax
||
a
is
ArrowExpressionClauseSyntax
||
a
is
ConstructorInitializerSyntax
).
LastOrDefault
();
}
private
bool
TryGetSpeculativeSemanticModel
(
SemanticModel
semanticModel
,
int
position
,
SyntaxNode
topmostContainer
,
out
SemanticModel
speculativeModel
)
{
switch
(
topmostContainer
)
{
case
StatementSyntax
statement
:
return
semanticModel
.
TryGetSpeculativeSemanticModel
(
position
,
statement
,
out
speculativeModel
);
case
EqualsValueClauseSyntax
equalsValue
:
return
semanticModel
.
TryGetSpeculativeSemanticModel
(
position
,
equalsValue
,
out
speculativeModel
);
case
ArrowExpressionClauseSyntax
arrowExpression
:
return
semanticModel
.
TryGetSpeculativeSemanticModel
(
position
,
arrowExpression
,
out
speculativeModel
);
case
ConstructorInitializerSyntax
constructorInitializer
:
return
semanticModel
.
TryGetSpeculativeSemanticModel
(
position
,
constructorInitializer
,
out
speculativeModel
);
}
speculativeModel
=
null
;
return
false
;
}
private
TypeSyntax
GetDeclarationType
(
TypeSyntax
type
,
bool
useVarWhenDeclaringLocals
,
bool
useImplicitTypeForIntrinsicTypes
)
{
...
...
src/Features/CSharp/Portable/InlineDeclaration/CSharpInlineDeclarationDiagnosticAnalyzer.cs
浏览文件 @
fce57c59
...
...
@@ -193,12 +193,12 @@ private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context, INamedTypeSymb
// The variable is read or written from outside the block that the new variable
// would be scoped in. This would cause a break.
//
// Note(cyrusn): We cou
dl
still offer the refactoring, but just show an error in the
// Note(cyrusn): We cou
ld
still offer the refactoring, but just show an error in the
// preview in this case.
return
;
}
// Make sure the variable isn't ever acessed before the usage in this out-var.
// Make sure the variable isn't ever ac
c
essed before the usage in this out-var.
if
(
IsAccessed
(
semanticModel
,
outSymbol
,
enclosingBlockOfLocalStatement
,
localStatement
,
argumentNode
,
cancellationToken
))
{
...
...
@@ -293,7 +293,7 @@ where outSymbol.Equals(symbol)
// NOTE: there is no current compiler API to determine if a variable is definitely
// assigned or not. So, for now, we just get diagnostics for this block and see if
// we get any definite assigment errors where we have a reference to the symbol. If
// we get any definite assig
n
ment errors where we have a reference to the symbol. If
// so, then we don't offer the fix.
rootWithoutInitializer
=
(
CompilationUnitSyntax
)
rootWithoutInitializerTree
.
GetRoot
(
cancellationToken
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录