Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fef6618d
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,发现更多精彩内容 >>
提交
fef6618d
编写于
10月 23, 2017
作者:
O
Omar Tawfik
提交者:
Sam Harwell
11月 02, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PR comments
上级
7f077aa3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
149 addition
and
15 deletion
+149
-15
src/EditorFeatures/CSharpTest/Diagnostics/UseImplicitOrExplicitType/UseImplicitTypeTests.cs
...nostics/UseImplicitOrExplicitType/UseImplicitTypeTests.cs
+140
-10
src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpUseImplicitTypeDiagnosticAnalyzer.cs
...tics/Analyzers/CSharpUseImplicitTypeDiagnosticAnalyzer.cs
+9
-5
未找到文件。
src/EditorFeatures/CSharpTest/Diagnostics/UseImplicitOrExplicitType/UseImplicitTypeTests.cs
浏览文件 @
fef6618d
...
...
@@ -1754,8 +1754,8 @@ static void M()
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
DoNotSuggestVarOnStackAllocExpressions_SpanType
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
namespace System
{
public readonly ref struct Span<T>
...
...
@@ -1776,8 +1776,8 @@ static void M()
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
DoNotSuggestVarOnStackAllocExpressions_SpanType_NestedConditional
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
namespace System
{
public readonly ref struct Span<T>
...
...
@@ -1798,8 +1798,8 @@ static void M(bool choice)
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
DoNotSuggestVarOnStackAllocExpressions_SpanType_NestedCast
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
await
TestMissingInRegularAndScriptAsync
(
@"
using System;
namespace System
{
public readonly ref struct Span<T>
...
...
@@ -1818,17 +1818,147 @@ static void M()
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExplicitType
)]
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
DoNotSuggestVarOnStackAllocExpressions_PointerType
()
public
async
Task
SuggestVarOnLambdasWithNestedStackAllocs
()
{
await
TestMissingInRegularAndScriptAsync
(
@"using System;
await
TestInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
unsafe static void M()
{
[|int|] x = new int[] { 1, 2, 3 }.First(i =>
{
int* y = stackalloc int[10];
return i == 1;
});
}
}"
,
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(i =>
{
int* y = stackalloc int[10];
return i == 1;
});
}
}"
,
options
:
ImplicitTypeEverywhere
());
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExplicitType
)]
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
SuggestVarOnAnonymousMethodsWithNestedStackAllocs
()
{
await
TestInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
unsafe static void M()
{
[|int|] x = new int[] { 1, 2, 3 }.First(delegate (int i)
{
int* y = stackalloc int[10];
return i == 1;
});
}
}"
,
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(delegate (int i)
{
int* y = stackalloc int[10];
return i == 1;
});
}
}"
,
options
:
ImplicitTypeEverywhere
());
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExplicitType
)]
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
SuggestVarOnStackAllocsNestedInLambdas
()
{
await
TestInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(i =>
{
[|int*|] y = stackalloc int[10];
return i == 1;
});
}
}"
,
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(i =>
{
var y = stackalloc int[10];
return i == 1;
});
}
}"
,
options
:
ImplicitTypeEverywhere
());
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExplicitType
)]
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
SuggestVarOnStackAllocsNestedInAnonymousMethods
()
{
await
TestInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(delegate (int i)
{
[|int*|] y = stackalloc int[10];
return i == 1;
});
}
}"
,
@"
using System.Linq;
class C
{
unsafe static void M()
{
var x = new int[] { 1, 2, 3 }.First(delegate (int i)
{
var y = stackalloc int[10];
return i == 1;
});
}
}"
,
options
:
ImplicitTypeEverywhere
());
}
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExplicitType
)]
[
WorkItem
(
22768
,
"https://github.com/dotnet/roslyn/issues/22768"
)]
public
async
Task
SuggestVarOnStackAllocsInOuterMethodScope
()
{
await
TestInRegularAndScriptAsync
(
@"
class C
{
unsafe static void M()
{
[|int*|] x = stackalloc int [10];
}
}"
,
new
TestParameters
(
options
:
ImplicitTypeEverywhere
()));
}"
,
@"
class C
{
unsafe static void M()
{
var x = stackalloc int [10];
}
}"
,
options
:
ImplicitTypeEverywhere
());
}
}
}
src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpUseImplicitTypeDiagnosticAnalyzer.cs
浏览文件 @
fef6618d
...
...
@@ -109,16 +109,20 @@ protected override bool TryAnalyzeVariableDeclaration(TypeSyntax typeName, Seman
var
variable
=
variableDeclaration
.
Variables
.
Single
();
var
initializer
=
variable
.
Initializer
.
Value
;
// Discourage using "var pointer = stackalloc", after introducing C# 7.2, as it might be confusing to users expecting a Span<>
// Check descendant nodes as well, because Span-creating stackallocs can be nested in other nodes (like conditional operators and casts).
// https://github.com/dotnet/roslyn/issues/22768
if
(
initializer
.
DescendantNodesAndSelf
().
Any
(
node
=>
node
.
IsKind
(
SyntaxKind
.
StackAllocArrayCreationExpression
)))
// Do not suggest var replacement for stackalloc span expressions.
// This will change the bound type from a span to a pointer.
if
(!
variableDeclaration
.
Type
.
IsKind
(
SyntaxKind
.
PointerType
)
&&
initializer
.
DescendantNodesAndSelf
(
descendIntoChildren
:
node
=>
!
node
.
IsAnyLambdaOrAnonymousMethod
())
.
Any
(
node
=>
node
.
IsKind
(
SyntaxKind
.
StackAllocArrayCreationExpression
)))
{
issueSpan
=
default
;
return
false
;
}
if
(
AssignmentSupportsStylePreference
(
variable
.
Identifier
,
typeName
,
initializer
,
semanticModel
,
optionSet
,
cancellationToken
))
if
(
AssignmentSupportsStylePreference
(
variable
.
Identifier
,
typeName
,
initializer
,
semanticModel
,
optionSet
,
cancellationToken
))
{
issueSpan
=
candidateIssueSpan
;
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录