Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
acd2f059
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,发现更多精彩内容 >>
提交
acd2f059
编写于
2月 10, 2016
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for VB params array Syntax properties
Also address code review comments.
上级
73bd858a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
16 deletion
+54
-16
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
+16
-15
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
...Sharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
+2
-0
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
...ore/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
+1
-1
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
...Basic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
+35
-0
未找到文件。
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
浏览文件 @
acd2f059
...
...
@@ -51,7 +51,7 @@ ImmutableArray<IArgument> IInvocationExpression.ArgumentsInSourceOrder
ArrayBuilder
<
IArgument
>
sourceOrderArguments
=
ArrayBuilder
<
IArgument
>.
GetInstance
(
this
.
Arguments
.
Length
);
for
(
int
argumentIndex
=
0
;
argumentIndex
<
this
.
Arguments
.
Length
;
argumentIndex
++)
{
IArgument
argument
=
DeriveArgument
(
this
.
ArgsToParamsOpt
.
IsDefault
?
argumentIndex
:
this
.
ArgsToParamsOpt
[
argumentIndex
],
argumentIndex
,
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Method
.
Parameters
);
IArgument
argument
=
DeriveArgument
(
this
.
ArgsToParamsOpt
.
IsDefault
?
argumentIndex
:
this
.
ArgsToParamsOpt
[
argumentIndex
],
argumentIndex
,
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Method
.
Parameters
,
this
.
Syntax
);
sourceOrderArguments
.
Add
(
argument
);
if
(
argument
.
ArgumentKind
==
ArgumentKind
.
ParamArray
)
{
...
...
@@ -63,11 +63,11 @@ ImmutableArray<IArgument> IInvocationExpression.ArgumentsInSourceOrder
}
}
ImmutableArray
<
IArgument
>
IInvocationExpression
.
ArgumentsInParameterOrder
=>
DeriveArguments
(
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Method
.
Parameters
);
ImmutableArray
<
IArgument
>
IInvocationExpression
.
ArgumentsInParameterOrder
=>
DeriveArguments
(
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Method
.
Parameters
,
this
.
Syntax
);
IArgument
IInvocationExpression
.
ArgumentMatchingParameter
(
IParameterSymbol
parameter
)
{
return
ArgumentMatchingParameter
(
this
.
Arguments
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
parameter
.
ContainingSymbol
as
Symbols
.
MethodSymbol
,
parameter
);
return
ArgumentMatchingParameter
(
this
.
Arguments
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
parameter
.
ContainingSymbol
as
Symbols
.
MethodSymbol
,
parameter
,
this
.
Syntax
);
}
protected
override
OperationKind
ExpressionKind
=>
OperationKind
.
InvocationExpression
;
...
...
@@ -82,7 +82,7 @@ public override void Accept(OperationVisitor visitor)
return
visitor
.
VisitInvocationExpression
(
this
,
argument
);
}
internal
static
ImmutableArray
<
IArgument
>
DeriveArguments
(
ImmutableArray
<
BoundExpression
>
boundArguments
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
int
>
argumentsToParameters
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
ImmutableArray
<
Symbols
.
ParameterSymbol
>
parameters
)
internal
static
ImmutableArray
<
IArgument
>
DeriveArguments
(
ImmutableArray
<
BoundExpression
>
boundArguments
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
int
>
argumentsToParameters
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
ImmutableArray
<
Symbols
.
ParameterSymbol
>
parameters
,
SyntaxNode
invocationSyntax
)
{
ArrayBuilder
<
IArgument
>
arguments
=
ArrayBuilder
<
IArgument
>.
GetInstance
(
boundArguments
.
Length
);
for
(
int
parameterIndex
=
0
;
parameterIndex
<
parameters
.
Length
;
parameterIndex
++)
...
...
@@ -112,12 +112,12 @@ internal static ImmutableArray<IArgument> DeriveArguments(ImmutableArray<BoundEx
{
// If corresponding parameter is Param array, then this means 0 element is provided and an Argument of kind == ParamArray will be added,
// otherwise it is an error and null is added.
arguments
.
Add
(
DeriveArgument
(
parameterIndex
,
argumentIndex
,
boundArguments
,
argumentNames
,
argumentRefKinds
,
parameters
));
arguments
.
Add
(
DeriveArgument
(
parameterIndex
,
argumentIndex
,
boundArguments
,
argumentNames
,
argumentRefKinds
,
parameters
,
invocationSyntax
));
}
}
else
{
arguments
.
Add
(
DeriveArgument
(
parameterIndex
,
argumentIndex
,
boundArguments
,
argumentNames
,
argumentRefKinds
,
parameters
));
arguments
.
Add
(
DeriveArgument
(
parameterIndex
,
argumentIndex
,
boundArguments
,
argumentNames
,
argumentRefKinds
,
parameters
,
invocationSyntax
));
}
}
...
...
@@ -126,7 +126,7 @@ internal static ImmutableArray<IArgument> DeriveArguments(ImmutableArray<BoundEx
private
static
readonly
ConditionalWeakTable
<
BoundExpression
,
IArgument
>
s_argumentMappings
=
new
ConditionalWeakTable
<
BoundExpression
,
IArgument
>();
private
static
IArgument
DeriveArgument
(
int
parameterIndex
,
int
argumentIndex
,
ImmutableArray
<
BoundExpression
>
boundArguments
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
ImmutableArray
<
Symbols
.
ParameterSymbol
>
parameters
)
private
static
IArgument
DeriveArgument
(
int
parameterIndex
,
int
argumentIndex
,
ImmutableArray
<
BoundExpression
>
boundArguments
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
ImmutableArray
<
Symbols
.
ParameterSymbol
>
parameters
,
SyntaxNode
invocationSyntax
)
{
if
(
argumentIndex
>=
boundArguments
.
Length
)
{
...
...
@@ -136,7 +136,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
Symbols
.
ParameterSymbol
lastParameter
=
parameters
[
parameters
.
Length
-
1
];
if
(
lastParameter
.
IsParams
)
{
return
new
Argument
(
ArgumentKind
.
ParamArray
,
lastParameter
,
CreateParamArray
(
lastParameter
,
boundArguments
,
argumentIndex
));
return
new
Argument
(
ArgumentKind
.
ParamArray
,
lastParameter
,
CreateParamArray
(
lastParameter
,
boundArguments
,
argumentIndex
,
invocationSyntax
));
}
}
...
...
@@ -167,7 +167,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
argument
.
Type
.
TypeKind
!=
TypeKind
.
Array
||
!
argument
.
Type
.
Equals
(
parameters
[
parameters
.
Length
-
1
].
Type
,
ignoreCustomModifiersAndArraySizesAndLowerBounds
:
true
)))
{
return
new
Argument
(
ArgumentKind
.
ParamArray
,
parameters
[
parameters
.
Length
-
1
],
CreateParamArray
(
parameters
[
parameters
.
Length
-
1
],
boundArguments
,
argumentIndex
));
return
new
Argument
(
ArgumentKind
.
ParamArray
,
parameters
[
parameters
.
Length
-
1
],
CreateParamArray
(
parameters
[
parameters
.
Length
-
1
],
boundArguments
,
argumentIndex
,
invocationSyntax
));
}
else
{
...
...
@@ -179,7 +179,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
});
}
private
static
IExpression
CreateParamArray
(
IParameterSymbol
parameter
,
ImmutableArray
<
BoundExpression
>
boundArguments
,
int
firstArgumentElementIndex
)
private
static
IExpression
CreateParamArray
(
IParameterSymbol
parameter
,
ImmutableArray
<
BoundExpression
>
boundArguments
,
int
firstArgumentElementIndex
,
SyntaxNode
invocationSyntax
)
{
if
(
parameter
.
Type
.
TypeKind
==
TypeKind
.
Array
)
{
...
...
@@ -192,18 +192,19 @@ private static IExpression CreateParamArray(IParameterSymbol parameter, Immutabl
}
var
paramArrayArguments
=
builder
.
ToImmutableAndFree
();
return
new
ArrayCreation
(
arrayType
,
paramArrayArguments
,
paramArrayArguments
.
Length
>
0
?
paramArrayArguments
[
0
].
Syntax
:
null
);
// Use the invocation syntax node if there is no actual syntax available for the argument (because the paramarray is empty.)
return
new
ArrayCreation
(
arrayType
,
paramArrayArguments
,
paramArrayArguments
.
Length
>
0
?
paramArrayArguments
[
0
].
Syntax
:
invocationSyntax
);
}
return
null
;
}
internal
static
IArgument
ArgumentMatchingParameter
(
ImmutableArray
<
BoundExpression
>
arguments
,
ImmutableArray
<
int
>
argumentsToParameters
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
Symbols
.
MethodSymbol
targetMethod
,
IParameterSymbol
parameter
)
internal
static
IArgument
ArgumentMatchingParameter
(
ImmutableArray
<
BoundExpression
>
arguments
,
ImmutableArray
<
int
>
argumentsToParameters
,
ImmutableArray
<
string
>
argumentNames
,
ImmutableArray
<
RefKind
>
argumentRefKinds
,
Symbols
.
MethodSymbol
targetMethod
,
IParameterSymbol
parameter
,
SyntaxNode
invocationSyntax
)
{
int
argumentIndex
=
ArgumentIndexMatchingParameter
(
arguments
,
argumentsToParameters
,
targetMethod
,
parameter
);
if
(
argumentIndex
>=
0
)
{
return
DeriveArgument
(
parameter
.
Ordinal
,
argumentIndex
,
arguments
,
argumentNames
,
argumentRefKinds
,
targetMethod
.
Parameters
);
return
DeriveArgument
(
parameter
.
Ordinal
,
argumentIndex
,
arguments
,
argumentNames
,
argumentRefKinds
,
targetMethod
.
Parameters
,
invocationSyntax
);
}
return
null
;
...
...
@@ -464,11 +465,11 @@ partial class BoundObjectCreationExpression : IObjectCreationExpression
IMethodSymbol
IObjectCreationExpression
.
Constructor
=>
this
.
Constructor
;
ImmutableArray
<
IArgument
>
IObjectCreationExpression
.
ConstructorArguments
=>
BoundCall
.
DeriveArguments
(
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Constructor
.
Parameters
);
ImmutableArray
<
IArgument
>
IObjectCreationExpression
.
ConstructorArguments
=>
BoundCall
.
DeriveArguments
(
this
.
Arguments
,
this
.
ArgumentNamesOpt
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Constructor
.
Parameters
,
this
.
Syntax
);
IArgument
IObjectCreationExpression
.
ArgumentMatchingParameter
(
IParameterSymbol
parameter
)
{
return
BoundCall
.
ArgumentMatchingParameter
(
this
.
Arguments
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Constructor
,
parameter
);
return
BoundCall
.
ArgumentMatchingParameter
(
this
.
Arguments
,
this
.
ArgsToParamsOpt
,
this
.
ArgumentNamesOpt
,
this
.
ArgumentRefKindsOpt
,
this
.
Constructor
,
parameter
,
this
.
Syntax
);
}
ImmutableArray
<
ISymbolInitializer
>
IObjectCreationExpression
.
MemberInitializers
...
...
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
浏览文件 @
acd2f059
...
...
@@ -1356,6 +1356,8 @@ public void M1()
CreateCompilationWithMscorlib45
(
source
)
.
VerifyDiagnostics
()
.
VerifyAnalyzerDiagnostics
(
new
DiagnosticAnalyzer
[]
{
new
NullOperationSyntaxTestAnalyzer
()
},
null
,
null
,
false
,
// TODO: missing a params array for M0()
// https://github.com/dotnet/roslyn/issues/8566
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"1"
).
WithLocation
(
11
,
12
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"1"
).
WithLocation
(
12
,
12
));
}
...
...
src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
acd2f059
...
...
@@ -1356,7 +1356,7 @@ public sealed override void Initialize(AnalysisContext context)
}
},
OperationKind
.
BlockStatement
);
OperationKind
.
InvocationExpression
);
}
// this OperationWalker collect:
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
浏览文件 @
acd2f059
...
...
@@ -1430,5 +1430,40 @@ End Class
Diagnostic
(
StaticMemberTestAnalyzer
.
StaticMemberDescriptor
.
Id
,
"D.P"
).
WithLocation
(
26
,
17
),
Diagnostic
(
StaticMemberTestAnalyzer
.
StaticMemberDescriptor
.
Id
,
"D.Method()"
).
WithLocation
(
27
,
9
))
End
Sub
<
Fact
>
Public
Sub
NullOperationSyntaxVisualBasic
()
Dim
source
=
<
compilation
>
<
file
name
=
"c.vb"
>
<
!
[
CDATA
[
Class
C
Public
Sub
M0
(
ParamArray
b
As
Integer
())
End
Sub
Public
Sub
M1
()
M0
()
M0
(
1
)
M0
(
1
,
2
)
M0
(
New
Integer
()
{
})
M0
(
New
Integer
()
{
1
})
M0
(
New
Integer
()
{
1
,
2
})
End
Sub
End
Class
]]
>
</
file
>
</
compilation
>
' TODO: array should not be treated as ParamArray argument
' https://github.com/dotnet/roslyn/issues/8570
Dim
comp
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyAnalyzerDiagnostics
({
New
NullOperationSyntaxTestAnalyzer
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"M0()"
).
WithLocation
(
6
,
9
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"M0(1)"
).
WithLocation
(
7
,
9
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"M0(1, 2)"
).
WithLocation
(
8
,
9
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"New Integer() { }"
).
WithLocation
(
9
,
12
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"New Integer() { 1 }"
).
WithLocation
(
10
,
12
),
Diagnostic
(
NullOperationSyntaxTestAnalyzer
.
ParamsArrayOperationDescriptor
.
Id
,
"New Integer() { 1, 2 }"
).
WithLocation
(
11
,
12
))
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录