Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f364873d
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,发现更多精彩内容 >>
未验证
提交
f364873d
编写于
8月 07, 2019
作者:
D
dotnet-automerge-bot
提交者:
GitHub
8月 07, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #37786 from dotnet/merges/master-to-master-vs-deps
Merge master to master-vs-deps
上级
f00691f5
51848948
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
141 addition
and
31 deletion
+141
-31
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
...itorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
+35
-1
src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs
...ntation/ProjectSystem/RunningDocumentTableEventTracker.cs
+1
-1
src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs
...es/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs
+5
-0
src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs
...arp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs
+1
-1
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
...nguageServices/CSharpTypeInferenceService.TypeInferrer.cs
+24
-28
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
+70
-0
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
.../Portable/Utilities/NullableHelpers/NullableExtensions.cs
+5
-0
未找到文件。
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
浏览文件 @
f364873d
...
...
@@ -3031,7 +3031,7 @@ static void Main(string[] args)
await
TestAsync
(
text
,
"global::Program"
,
testNode
:
false
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/37310"
)
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestInferringThroughGenericFunctionWithNullableReturn
()
{
var
text
=
...
...
@@ -3049,5 +3049,39 @@ static void Main(string[] args)
await
TestAsync
(
text
,
"global::System.String?"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestInferringThroughGenericFunctionMissingArgument
()
{
var
text
=
@"class Program
{
static void Main(string[] args)
{
string s = Identity([||]);
}
static T Identity<T>(T value) { return value; }
}"
;
await
TestAsync
(
text
,
"global::System.String"
,
testNode
:
false
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestInferringThroughGenericFunctionTooManyArguments
()
{
var
text
=
@"class Program
{
static void Main(string[] args)
{
string s = Identity(""test"", [||]);
}
static T Identity<T>(T value) { return value; }
}"
;
await
TestAsync
(
text
,
"global::System.Object"
);
}
}
}
src/VisualStudio/Core/Def/Implementation/ProjectSystem/RunningDocumentTableEventTracker.cs
浏览文件 @
f364873d
...
...
@@ -34,12 +34,12 @@ internal sealed class RunningDocumentTableEventTracker : IVsRunningDocTableEvent
Contract
.
ThrowIfNull
(
runningDocumentTable
);
Contract
.
ThrowIfNull
(
listener
);
// Advise / Unadvise for the RDT is free threaded past 16.0
_foregroundAffinitization
=
new
ForegroundThreadAffinitizedObject
(
threadingContext
,
assertIsForeground
:
false
);
_runningDocumentTable
=
(
IVsRunningDocumentTable4
)
runningDocumentTable
;
_editorAdaptersFactoryService
=
editorAdaptersFactoryService
;
_listener
=
listener
;
// Advise / Unadvise for the RDT is free threaded past 16.0
((
IVsRunningDocumentTable
)
_runningDocumentTable
).
AdviseRunningDocTableEvents
(
this
,
out
_runningDocumentTableEventsCookie
);
}
...
...
src/Workspaces/CSharp/Portable/Formatting/Rules/BaseFormattingRule.cs
浏览文件 @
f364873d
...
...
@@ -184,6 +184,11 @@ protected void AddBraceSuppressOperations(List<SuppressOperation> list, SyntaxNo
// include lambda itself.
firstTokenOfNode
=
node
.
Parent
.
GetFirstToken
(
includeZeroWidth
:
true
);
}
else
if
(
node
.
IsKind
(
SyntaxKindEx
.
PropertyPatternClause
))
{
// include the pattern recursive pattern syntax and/or subpattern
firstTokenOfNode
=
firstTokenOfNode
.
GetPreviousToken
();
}
// suppress wrapping on whole construct that owns braces and also brace pair itself if
// it is on same line
...
...
src/Workspaces/CSharp/Portable/Formatting/Rules/TokenBasedFormattingRule.cs
浏览文件 @
f364873d
...
...
@@ -370,7 +370,7 @@ public override AdjustSpacesOperation GetAdjustSpacesOperation(SyntaxToken previ
// nullable
if
(
currentToken
.
Kind
()
==
SyntaxKind
.
QuestionToken
&&
currentToken
.
Parent
.
Kind
()
==
SyntaxKind
.
NullableType
)
currentToken
.
Parent
.
IsKind
(
SyntaxKind
.
NullableType
,
SyntaxKind
.
ClassConstraint
)
)
{
return
CreateAdjustSpacesOperation
(
0
,
AdjustSpacesOption
.
ForceSpacesIfOnSingleLine
);
}
...
...
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
浏览文件 @
f364873d
...
...
@@ -345,7 +345,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInAnonymousObjectCreation(Anonym
.
Select
(
tupleType
=>
new
TypeInferenceInfo
(
tupleType
.
TupleElements
[
index
].
GetTypeWithAnnotatedNullability
()));
}
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInAttributeArgument
(
AttributeArgumentSyntax
argument
,
SyntaxToken
?
previousToken
=
null
,
ArgumentSyntax
argumentOpt
=
null
)
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInAttributeArgument
(
AttributeArgumentSyntax
argument
,
SyntaxToken
?
previousToken
=
null
)
{
if
(
previousToken
.
HasValue
)
{
...
...
@@ -372,7 +372,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInConstructorInitializer(Constru
{
var
info
=
SemanticModel
.
GetSymbolInfo
(
initializer
,
CancellationToken
);
var
methods
=
info
.
GetBestOrAllSymbols
().
OfType
<
IMethodSymbol
>();
return
InferTypeInArgument
(
index
,
methods
,
argument
);
return
InferTypeInArgument
(
index
,
methods
,
argument
,
parentInvocationExpressionToTypeInfer
:
null
);
}
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInObjectCreationExpression
(
ObjectCreationExpressionSyntax
expression
,
SyntaxToken
previousToken
)
...
...
@@ -435,7 +435,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInObjectCreationExpression(Objec
}
var
constructors
=
type
.
InstanceConstructors
.
Where
(
m
=>
m
.
Parameters
.
Length
>
index
);
return
InferTypeInArgument
(
index
,
constructors
,
argumentOpt
);
return
InferTypeInArgument
(
index
,
constructors
,
argumentOpt
,
parentInvocationExpressionToTypeInfer
:
null
);
}
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInInvocationExpression
(
...
...
@@ -460,7 +460,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInObjectCreationExpression(Objec
methods
=
methods
.
Concat
(
memberGroupMethods
).
Distinct
();
}
return
InferTypeInArgument
(
index
,
methods
,
argumentOpt
);
return
InferTypeInArgument
(
index
,
methods
,
argumentOpt
,
invocation
);
}
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInArgumentList
(
ArgumentListSyntax
argumentList
,
SyntaxToken
previousToken
)
...
...
@@ -549,29 +549,26 @@ private IEnumerable<TypeInferenceInfo> InferTypeInAttributeArgument(int index, I
return
InferTypeInAttributeArgument
(
index
,
methods
.
Select
(
m
=>
m
.
Parameters
),
argumentOpt
);
}
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInArgument
(
int
index
,
IEnumerable
<
IMethodSymbol
>
methods
,
ArgumentSyntax
argumentOpt
)
private
IEnumerable
<
TypeInferenceInfo
>
InferTypeInArgument
(
int
index
,
IEnumerable
<
IMethodSymbol
>
methods
,
ArgumentSyntax
argumentOpt
,
InvocationExpressionSyntax
parentInvocationExpressionToTypeInfer
)
{
if
(
argumentOpt
!=
null
)
if
(
parentInvocationExpressionToTypeInfer
!=
null
)
{
if
(
argumentOpt
?.
Parent
?.
Parent
is
InvocationExpressionSyntax
invocation
)
{
// We're trying to figure out the signature of a method we're an argument to.
// That method may be generic, and we might end up using one of its generic
// type parameters in the type we infer. First, let's see if we can instantiate
// the methods so that the type can be inferred better.
var
invocationTypes
=
this
.
InferTypes
(
invocation
).
Select
(
t
=>
t
.
InferredType
).
ToList
();
var
instantiatedMethods
=
methods
.
Select
(
m
=>
Instantiate
(
m
,
invocationTypes
)).
ToList
();
// Now that we've instantiated the methods, filter down to the ones that
// will actually return a viable type given where this invocation expression
// is.
var
filteredMethods
=
instantiatedMethods
.
Where
(
m
=>
invocationTypes
.
Any
(
t
=>
Compilation
.
ClassifyConversion
(
m
.
ReturnType
.
WithoutNullability
(),
t
.
WithoutNullability
()).
IsImplicit
)).
ToList
();
// If we filtered down to nothing, then just fall back to the instantiated list.
// this is a best effort after all.
methods
=
filteredMethods
.
Any
()
?
filteredMethods
:
instantiatedMethods
;
}
// We're trying to figure out the signature of a method we're an argument to.
// That method may be generic, and we might end up using one of its generic
// type parameters in the type we infer. First, let's see if we can instantiate
// the methods so that the type can be inferred better.
var
invocationTypes
=
this
.
InferTypes
(
parentInvocationExpressionToTypeInfer
).
Select
(
t
=>
t
.
InferredType
).
ToList
();
var
instantiatedMethods
=
methods
.
Select
(
m
=>
Instantiate
(
m
,
invocationTypes
)).
ToList
();
// Now that we've instantiated the methods, filter down to the ones that
// will actually return a viable type given where this invocation expression
// is.
var
filteredMethods
=
instantiatedMethods
.
Where
(
m
=>
invocationTypes
.
Any
(
t
=>
Compilation
.
ClassifyConversion
(
m
.
ReturnType
.
WithoutNullability
(),
t
.
WithoutNullability
()).
IsImplicit
)).
ToList
();
// If we filtered down to nothing, then just fall back to the instantiated list.
// this is a best effort after all.
methods
=
filteredMethods
.
Any
()
?
filteredMethods
:
instantiatedMethods
;
}
return
InferTypeInArgument
(
index
,
methods
.
Select
(
m
=>
m
.
Parameters
),
argumentOpt
);
...
...
@@ -618,10 +615,9 @@ private IMethodSymbol Instantiate(IMethodSymbol method, IList<ITypeSymbol> invoc
return
method
;
}
// TODO: pass nullability once https://github.com/dotnet/roslyn/issues/37310 is fixed
var
typeArguments
=
method
.
ConstructedFrom
.
TypeParameters
.
Select
(
tp
=>
(
bestMap
.
GetValueOrDefault
(
tp
)
??
tp
).
WithoutNullability
()
).
ToArray
();
return
method
.
ConstructedFrom
.
Construct
(
typeArguments
);
.
Select
(
tp
=>
bestMap
.
GetValueOrDefault
(
tp
)
??
tp
).
ToArray
();
return
method
.
ConstructedFrom
.
Construct
WithNullability
(
typeArguments
);
}
private
Dictionary
<
ITypeParameterSymbol
,
ITypeSymbol
>
DetermineTypeParameterMapping
(
ITypeSymbol
inferredType
,
ITypeSymbol
returnType
)
...
...
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
浏览文件 @
f364873d
...
...
@@ -9280,5 +9280,75 @@ public void FixMyType()
}
}"
,
changedOptionSet
:
changingOptions
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
async
Task
ClassConstraint
()
{
await
AssertFormatAsync
(
@"
class Program<T>
where T : class?
{
}"
,
@"
class Program<T>
where T : class ?
{
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
async
Task
SingleLinePropertyPattern1
()
{
await
AssertFormatAsync
(
@"
using System.Collections.Generic;
class Program
{
public void FixMyType()
{
_ = new List<int>() is
{
Count: { },
};
}
}"
,
@"
using System.Collections.Generic;
class Program
{
public void FixMyType()
{
_ = new List<int>() is
{
Count:{},
};
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
async
Task
SingleLinePropertyPattern2
()
{
await
AssertFormatAsync
(
@"
using System.Collections.Generic;
class Program
{
public void FixMyType(object o)
{
_ = o is List<int> { Count: { } };
}
}"
,
@"
using System.Collections.Generic;
class Program
{
public void FixMyType(object o)
{
_ = o is List<int>{Count:{}};
}
}"
);
}
}
}
src/Workspaces/Core/Portable/Utilities/NullableHelpers/NullableExtensions.cs
浏览文件 @
f364873d
...
...
@@ -115,5 +115,10 @@ public static INamedTypeSymbol ConstructWithNullability(this INamedTypeSymbol ty
{
return
typeSymbol
.
Construct
(
typeArguments
.
SelectAsArray
(
t
=>
t
.
WithoutNullability
()),
typeArguments
.
SelectAsArray
(
t
=>
t
.
GetNullability
()));
}
public
static
IMethodSymbol
ConstructWithNullability
(
this
IMethodSymbol
methodSymbol
,
params
ITypeSymbol
[]
typeArguments
)
{
return
methodSymbol
.
Construct
(
typeArguments
.
SelectAsArray
(
t
=>
t
.
WithoutNullability
()),
typeArguments
.
SelectAsArray
(
t
=>
t
.
GetNullability
()));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录