Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
98d7a9c0
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,发现更多精彩内容 >>
提交
98d7a9c0
编写于
1月 13, 2016
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address review comments
上级
e89d04ca
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
200 addition
and
200 deletion
+200
-200
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
+44
-48
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
+12
-17
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
...Sharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
+24
-8
src/Compilers/Core/Portable/Compilation/Expression.cs
src/Compilers/Core/Portable/Compilation/Expression.cs
+1
-1
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
+78
-87
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
+35
-37
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
...Basic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
+6
-2
未找到文件。
src/Compilers/CSharp/Portable/BoundTree/Expression.cs
浏览文件 @
98d7a9c0
...
...
@@ -83,11 +83,11 @@ public override BoundNode Visit(BoundNode node)
// (but not their children), since they are not statements in this case.
public
override
BoundNode
VisitMultipleLocalDeclarations
(
BoundMultipleLocalDeclarations
node
)
{
foreach
(
var
decl
in
node
.
LocalDeclarations
)
foreach
(
var
decl
aration
in
node
.
LocalDeclarations
)
{
this
.
Visit
(
decl
.
DeclaredType
);
this
.
Visit
(
decl
.
InitializerOpt
);
this
.
VisitList
(
decl
.
ArgumentsOpt
);
this
.
Visit
(
decl
aration
.
DeclaredType
);
this
.
Visit
(
decl
aration
.
InitializerOpt
);
this
.
VisitList
(
decl
aration
.
ArgumentsOpt
);
}
return
null
;
}
...
...
@@ -96,8 +96,13 @@ public override BoundNode VisitMultipleLocalDeclarations(BoundMultipleLocalDecla
// The corresponding operations are covered by `IMemberInitializer`.
public
override
BoundNode
VisitObjectInitializerExpression
(
BoundObjectInitializerExpression
node
)
{
foreach
(
BoundAssignmentOperator
assignment
in
node
.
Initializers
)
foreach
(
var
expression
in
node
.
Initializers
)
{
if
(
expression
.
HasErrors
)
{
continue
;
}
var
assignment
=
(
BoundAssignmentOperator
)
expression
;
this
.
Visit
(
assignment
.
Left
);
this
.
Visit
(
assignment
.
Right
);
}
...
...
@@ -184,7 +189,7 @@ internal static ImmutableArray<IArgument> DeriveArguments(ImmutableArray<BoundEx
return
arguments
.
ToImmutableAndFree
();
}
private
static
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
<
BoundExpression
,
IArgument
>
ArgumentMappings
=
new
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
<
BoundExpression
,
IArgument
>();
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
)
{
...
...
@@ -204,7 +209,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
return
null
;
}
return
A
rgumentMappings
.
GetValue
(
return
s_a
rgumentMappings
.
GetValue
(
boundArguments
[
argumentIndex
],
(
argument
)
=>
{
...
...
@@ -216,7 +221,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
if
(
refMode
!=
RefKind
.
None
)
{
return
(
IArgument
)
new
Argument
(
ArgumentKind
.
Positional
,
parameters
[
parameterIndex
],
argument
);
return
new
Argument
(
ArgumentKind
.
Positional
,
parameters
[
parameterIndex
],
argument
);
}
if
(
argumentIndex
>=
parameters
.
Length
-
1
&&
...
...
@@ -227,7 +232,7 @@ private static IArgument DeriveArgument(int parameterIndex, int argumentIndex, I
argument
.
Type
.
TypeKind
!=
TypeKind
.
Array
||
!
argument
.
Type
.
Equals
(
parameters
[
parameters
.
Length
-
1
].
Type
,
true
)))
{
return
(
IArgument
)
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
));
}
else
{
...
...
@@ -284,16 +289,14 @@ static int ArgumentIndexMatchingParameter(ImmutableArray<BoundExpression> argume
return
-
1
;
}
class
SimpleArgument
:
IArgument
abstract
class
ArgumentBase
:
IArgument
{
public
SimpleArgument
(
IParameterSymbol
parameter
,
IExpression
value
)
public
ArgumentBase
(
IParameterSymbol
parameter
,
IExpression
value
)
{
this
.
Value
=
value
;
this
.
Parameter
=
parameter
;
}
public
ArgumentKind
ArgumentKind
=>
ArgumentKind
.
Positional
;
public
IParameterSymbol
Parameter
{
get
;
}
public
IExpression
Value
{
get
;
}
...
...
@@ -307,32 +310,28 @@ public SimpleArgument(IParameterSymbol parameter, IExpression value)
OperationKind
IOperation
.
Kind
=>
OperationKind
.
Argument
;
SyntaxNode
IOperation
.
Syntax
=>
this
.
Value
.
Syntax
;
public
abstract
ArgumentKind
ArgumentKind
{
get
;
}
}
class
Argument
:
IArgument
class
SimpleArgument
:
ArgumentBase
{
public
SimpleArgument
(
IParameterSymbol
parameter
,
IExpression
value
)
:
base
(
parameter
,
value
)
{
}
public
override
ArgumentKind
ArgumentKind
=>
ArgumentKind
.
Positional
;
}
class
Argument
:
ArgumentBase
{
public
Argument
(
ArgumentKind
kind
,
IParameterSymbol
parameter
,
IExpression
value
)
:
base
(
parameter
,
value
)
{
this
.
Value
=
value
;
this
.
ArgumentKind
=
kind
;
this
.
Parameter
=
parameter
;
}
public
ArgumentKind
ArgumentKind
{
get
;
}
public
IParameterSymbol
Parameter
{
get
;
}
public
IExpression
Value
{
get
;
}
IExpression
IArgument
.
InConversion
=>
null
;
IExpression
IArgument
.
OutConversion
=>
null
;
bool
IOperation
.
IsInvalid
=>
this
.
Parameter
==
null
||
this
.
Value
.
IsInvalid
;
OperationKind
IOperation
.
Kind
=>
OperationKind
.
Argument
;
SyntaxNode
IOperation
.
Syntax
=>
this
.
Value
.
Syntax
;
public
override
ArgumentKind
ArgumentKind
{
get
;
}
}
}
...
...
@@ -431,8 +430,8 @@ partial class BoundLiteral : ILiteralExpression
partial
class
BoundObjectCreationExpression
:
IObjectCreationExpression
{
private
static
readonly
ConditionalWeakTable
<
BoundObjectCreationExpression
,
IMemberInitializer
[
]
>
s_memberInitializersMappings
=
new
ConditionalWeakTable
<
BoundObjectCreationExpression
,
IMemberInitializer
[
]
>
();
private
static
readonly
ConditionalWeakTable
<
BoundObjectCreationExpression
,
object
>
s_memberInitializersMappings
=
new
ConditionalWeakTable
<
BoundObjectCreationExpression
,
object
>();
IMethodSymbol
IObjectCreationExpression
.
Constructor
=>
this
.
Constructor
;
...
...
@@ -447,17 +446,17 @@ ImmutableArray<IMemberInitializer> IObjectCreationExpression.MemberInitializers
{
get
{
var
initializers
=
s_memberInitializersMappings
.
GetValue
(
this
,
obj
CreationExp
=>
return
(
ImmutableArray
<
IMemberInitializer
>)
s_memberInitializersMappings
.
GetValue
(
this
,
obj
ectCreationExpression
=>
{
BoundExpression
initializer
=
this
.
InitializerExpressionOpt
;
if
(
initializer
!=
null
)
{
var
obj
InitializerExp
=
initializer
as
BoundObjectInitializerExpression
;
if
(
obj
InitializerExp
!=
null
)
var
obj
ectInitializerExpression
=
initializer
as
BoundObjectInitializerExpression
;
if
(
obj
ectInitializerExpression
!=
null
)
{
var
builder
=
ArrayBuilder
<
IMemberInitializer
>.
GetInstance
(
obj
InitializerExp
.
Initializers
.
Length
);
foreach
(
var
memberAssignment
in
obj
InitializerExp
.
Initializers
)
var
builder
=
ArrayBuilder
<
IMemberInitializer
>.
GetInstance
(
obj
ectInitializerExpression
.
Initializers
.
Length
);
foreach
(
var
memberAssignment
in
obj
ectInitializerExpression
.
Initializers
)
{
var
assignment
=
memberAssignment
as
BoundAssignmentOperator
;
var
leftSymbol
=
(
assignment
?.
Left
as
BoundObjectInitializerMember
)?.
MemberSymbol
;
...
...
@@ -477,14 +476,11 @@ ImmutableArray<IMemberInitializer> IObjectCreationExpression.MemberInitializers
break
;
}
}
return
builder
.
To
Array
AndFree
();
return
builder
.
To
Immutable
AndFree
();
}
}
return
new
IMemberInitializer
[]
{
};
});
var
immBuilder
=
ArrayBuilder
<
IMemberInitializer
>.
GetInstance
(
initializers
.
Length
);
immBuilder
.
AddRange
(
initializers
);
return
immBuilder
.
ToImmutableAndFree
();
return
ImmutableArray
<
IMemberInitializer
>.
Empty
;
});
}
}
...
...
@@ -767,9 +763,9 @@ partial class BoundIncrementOperator : IIncrementExpression
IReferenceExpression
IAssignmentExpression
.
Target
=>
this
.
Operand
as
IReferenceExpression
;
private
static
readonly
ConditionalWeakTable
<
BoundIncrementOperator
,
IExpression
>
IncrementValueMappings
=
new
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
<
BoundIncrementOperator
,
IExpression
>();
private
static
readonly
ConditionalWeakTable
<
BoundIncrementOperator
,
IExpression
>
s_incrementValueMappings
=
new
ConditionalWeakTable
<
BoundIncrementOperator
,
IExpression
>();
IExpression
IAssignmentExpression
.
Value
=>
I
ncrementValueMappings
.
GetValue
(
this
,
(
increment
)
=>
new
BoundLiteral
(
this
.
Syntax
,
Semantics
.
Expression
.
SynthesizeNumeric
(
increment
.
Type
,
1
),
increment
.
Type
));
IExpression
IAssignmentExpression
.
Value
=>
s_i
ncrementValueMappings
.
GetValue
(
this
,
(
increment
)
=>
new
BoundLiteral
(
this
.
Syntax
,
Semantics
.
Expression
.
SynthesizeNumeric
(
increment
.
Type
,
1
),
increment
.
Type
));
bool
IHasOperatorExpression
.
UsesOperatorMethod
=>
(
this
.
OperatorKind
&
UnaryOperatorKind
.
TypeMask
)
==
UnaryOperatorKind
.
UserDefined
;
...
...
src/Compilers/CSharp/Portable/BoundTree/Statement.cs
浏览文件 @
98d7a9c0
...
...
@@ -322,17 +322,15 @@ partial class BoundStateMachineScope
partial
class
BoundLocalDeclaration
:
IVariableDeclarationStatement
{
private
static
readonly
ConditionalWeakTable
<
BoundLocalDeclaration
,
IVariable
>
s_variablesMappings
=
new
ConditionalWeakTable
<
BoundLocalDeclaration
,
IVariable
>();
private
static
readonly
ConditionalWeakTable
<
BoundLocalDeclaration
,
object
>
s_variablesMappings
=
new
ConditionalWeakTable
<
BoundLocalDeclaration
,
object
>();
ImmutableArray
<
IVariable
>
IVariableDeclarationStatement
.
Variables
{
get
{
var
builder
=
ArrayBuilder
<
IVariable
>.
GetInstance
(
1
);
var
variable
=
s_variablesMappings
.
GetValue
(
this
,
decl
=>
new
VariableDeclaration
(
decl
.
LocalSymbol
,
decl
.
InitializerOpt
,
decl
.
Syntax
));
builder
.
Add
(
variable
);
return
builder
.
ToImmutableAndFree
();
return
(
ImmutableArray
<
IVariable
>)
s_variablesMappings
.
GetValue
(
this
,
declaration
=>
ImmutableArray
.
Create
<
IVariable
>(
new
VariableDeclaration
(
declaration
.
LocalSymbol
,
declaration
.
InitializerOpt
,
declaration
.
Syntax
)));
}
}
...
...
@@ -341,26 +339,23 @@ ImmutableArray<IVariable> IVariableDeclarationStatement.Variables
partial
class
BoundMultipleLocalDeclarations
:
IVariableDeclarationStatement
{
private
static
readonly
ConditionalWeakTable
<
BoundMultipleLocalDeclarations
,
IVariable
[
]
>
s_variablesMappings
=
new
ConditionalWeakTable
<
BoundMultipleLocalDeclarations
,
IVariable
[
]
>
();
private
static
readonly
ConditionalWeakTable
<
BoundMultipleLocalDeclarations
,
object
>
s_variablesMappings
=
new
ConditionalWeakTable
<
BoundMultipleLocalDeclarations
,
object
>();
ImmutableArray
<
IVariable
>
IVariableDeclarationStatement
.
Variables
{
get
{
var
variables
=
s_variablesMappings
.
GetValue
(
this
,
multi
Decl
s
=>
return
(
ImmutableArray
<
IVariable
>)
s_variablesMappings
.
GetValue
(
this
,
multi
pleDeclaration
s
=>
{
var
arrBuilder
=
ArrayBuilder
<
IVariable
>.
GetInstance
(
multiDecl
s
.
LocalDeclarations
.
Length
);
foreach
(
var
decl
in
multiDecl
s
.
LocalDeclarations
)
var
builder
=
ArrayBuilder
<
IVariable
>.
GetInstance
(
multipleDeclaration
s
.
LocalDeclarations
.
Length
);
foreach
(
var
decl
aration
in
multipleDeclaration
s
.
LocalDeclarations
)
{
arrBuilder
.
Add
((
IVariable
)
new
VariableDeclaration
(
decl
.
LocalSymbol
,
decl
.
InitializerOpt
,
decl
.
Syntax
));
builder
.
Add
((
IVariable
)
new
VariableDeclaration
(
declaration
.
LocalSymbol
,
declaration
.
InitializerOpt
,
declaration
.
Syntax
));
}
return
arrBuilder
.
ToArray
AndFree
();
return
builder
.
ToImmutable
AndFree
();
});
var
immBuilder
=
ArrayBuilder
<
IVariable
>.
GetInstance
(
variables
.
Length
);
immBuilder
.
AddRange
(
variables
);
return
immBuilder
.
ToImmutableAndFree
();
}
}
...
...
src/Compilers/CSharp/Test/Semantic/Diagnostics/OperationAnalyzerTests.cs
浏览文件 @
98d7a9c0
...
...
@@ -812,24 +812,40 @@ class Foo
class C
{
public void M1()
{
{
var x1 = new Foo();
var x2 = new Foo() { Field = 2};
var x3 = new Foo() { Property1 = """"};
var x4 = new Foo() { Property1 = """", Field = 2};
var x5 = new Foo() { Property2 = new Bar { Field = true } };
var e1 = new Foo() { Property2 = 1 };
var e2 = new Foo() { "" };
}
}
"
;
CreateCompilationWithMscorlib45
(
source
)
.
VerifyDiagnostics
()
.
VerifyDiagnostics
(
// (25,30): error CS1010: Newline in constant
// var e2 = new Foo() { " };
Diagnostic
(
ErrorCode
.
ERR_NewlineInConst
,
""
).
WithLocation
(
25
,
30
),
// (26,6): error CS1002: ; expected
// }
Diagnostic
(
ErrorCode
.
ERR_SemicolonExpected
,
""
).
WithLocation
(
26
,
6
),
// (27,2): error CS1513: } expected
// }
Diagnostic
(
ErrorCode
.
ERR_RbraceExpected
,
""
).
WithLocation
(
27
,
2
),
// (24,42): error CS0029: Cannot implicitly convert type 'int' to 'Bar'
// var e1 = new Foo() { Property2 = 1 };
Diagnostic
(
ErrorCode
.
ERR_NoImplicitConv
,
"1"
).
WithArguments
(
"int"
,
"Bar"
).
WithLocation
(
24
,
42
))
.
VerifyAnalyzerDiagnostics
(
new
DiagnosticAnalyzer
[]
{
new
MemberInitializerTestAnalyzer
()
},
null
,
null
,
false
,
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = 2"
).
WithLocation
(
19
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
@"Property1 = """""
).
WithLocation
(
20
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
@"Property1 = """""
).
WithLocation
(
21
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = 2"
).
WithLocation
(
21
,
46
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
"Property2 = new Bar { Field = true }"
).
WithLocation
(
22
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = true"
).
WithLocation
(
22
,
52
));
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = 2"
).
WithLocation
(
19
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
@"Property1 = """""
).
WithLocation
(
20
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
@"Property1 = """""
).
WithLocation
(
21
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = 2"
).
WithLocation
(
21
,
46
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
"Property2 = new Bar { Field = true }"
).
WithLocation
(
22
,
30
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
"Field = true"
).
WithLocation
(
22
,
52
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
"Property2 = 1"
).
WithLocation
(
24
,
30
));
}
[
Fact
]
...
...
src/Compilers/Core/Portable/Compilation/Expression.cs
浏览文件 @
98d7a9c0
...
...
@@ -317,7 +317,7 @@ private class ArrayInitializer : IArrayInitializer
{
public
ArrayInitializer
(
ImmutableArray
<
IExpression
>
elementValues
,
SyntaxNode
syntax
,
ITypeSymbol
arrayType
)
{
ArrayBuilder
<
IExpression
>
builder
=
ArrayBuilder
<
IExpression
>.
GetInstance
();
ArrayBuilder
<
IExpression
>
builder
=
ArrayBuilder
<
IExpression
>.
GetInstance
(
elementValues
.
Length
);
foreach
(
IExpression
element
in
elementValues
)
{
builder
.
Add
(
element
);
...
...
src/Compilers/VisualBasic/Portable/BoundTree/Expression.vb
浏览文件 @
98d7a9c0
...
...
@@ -41,9 +41,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Case
OperationKind
.
InvocationExpression
Me
.
nodes
.
AddRange
(
DirectCast
(
operation
,
IInvocationExpression
).
ArgumentsInSourceOrder
)
Case
OperationKind
.
ObjectCreationExpression
Dim
obj
CreationExp
=
DirectCast
(
operation
,
IObjectCreationExpression
)
Me
.
nodes
.
AddRange
(
obj
CreationExp
.
ConstructorArguments
)
Me
.
nodes
.
AddRange
(
obj
CreationExp
.
MemberInitializers
)
Dim
obj
ectCreationExpression
=
DirectCast
(
operation
,
IObjectCreationExpression
)
Me
.
nodes
.
AddRange
(
obj
ectCreationExpression
.
ConstructorArguments
)
Me
.
nodes
.
AddRange
(
obj
ectCreationExpression
.
MemberInitializers
)
Case
OperationKind
.
SwitchSection
' "Case Else" clause is not a bound node, so it needs to be added explicitly.
Dim
caseClauses
=
DirectCast
(
operation
,
ICase
).
Clauses
...
...
@@ -66,7 +66,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' Skip visiting `BoundAssignmentOperator` nodes (but Not their children) if they are used for initializing members in object creation.
' The corresponding operations are covered by `IMemberInitializer`.
Public
Overrides
Function
VisitObjectInitializerExpression
(
node
As
BoundObjectInitializerExpression
)
As
BoundNode
For
Each
assignment
As
BoundAssignmentOperator
In
node
.
Initializers
For
Each
expression
In
node
.
Initializers
If
expression
.
HasErrors
Then
Continue
For
End
If
Dim
assignment
=
DirectCast
(
expression
,
BoundAssignmentOperator
)
Me
.
Visit
(
assignment
.
Left
)
Me
.
Visit
(
assignment
.
LeftOnTheRightOpt
)
Me
.
Visit
(
assignment
.
Right
)
...
...
@@ -374,61 +378,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
arguments
.
ToImmutable
()
End
Function
Private
Shared
A
rgumentMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundExpression
,
IArgument
)
Private
Shared
ReadOnly
s_a
rgumentMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundExpression
,
IArgument
)
Private
Shared
Function
DeriveArgument
(
index
As
Integer
,
argument
As
BoundExpression
,
parameters
As
ImmutableArray
(
Of
Symbols
.
ParameterSymbol
))
As
IArgument
Select
Case
argument
.
Kind
Case
BoundKind
.
ByRefArgumentWithCopyBack
Return
A
rgumentMappings
.
GetValue
(
argument
,
Function
(
a
)
New
ByRefArgument
(
parameters
(
index
),
DirectCast
(
argument
,
BoundByRefArgumentWithCopyBack
)))
Return
s_a
rgumentMappings
.
GetValue
(
argument
,
Function
(
a
)
New
ByRefArgument
(
parameters
(
index
),
DirectCast
(
argument
,
BoundByRefArgumentWithCopyBack
)))
Case
Else
' Apparently the VB bound trees don't encode named arguments, which seems unnecesarily lossy.
Return
A
rgumentMappings
.
GetValue
(
argument
,
Function
(
a
)
If
(
index
>=
parameters
.
Length
-
1
AndAlso
parameters
.
Length
>
0
AndAlso
parameters
(
parameters
.
Length
-
1
).
IsParamArray
,
New
Argument
(
ArgumentKind
.
ParamArray
,
parameters
(
parameters
.
Length
-
1
),
a
),
New
Argument
(
ArgumentKind
.
Positional
,
parameters
(
index
),
a
)))
Return
s_a
rgumentMappings
.
GetValue
(
argument
,
Function
(
a
)
If
(
index
>=
parameters
.
Length
-
1
AndAlso
parameters
.
Length
>
0
AndAlso
parameters
(
parameters
.
Length
-
1
).
IsParamArray
,
New
Argument
(
ArgumentKind
.
ParamArray
,
parameters
(
parameters
.
Length
-
1
),
a
),
New
Argument
(
ArgumentKind
.
Positional
,
parameters
(
index
),
a
)))
End
Select
End
Function
Private
Class
Argument
Private
MustInherit
Class
ArgumentBase
Implements
IArgument
Private
ReadOnly
_value
As
IExpression
Private
ReadOnly
_kind
As
ArgumentKind
Private
ReadOnly
_parameter
As
IParameterSymbol
Public
Sub
New
(
kind
As
ArgumentKind
,
parameter
As
IParameterSymbol
,
value
As
IExpression
)
_value
=
value
_kind
=
kind
Public
Sub
New
(
parameter
As
IParameterSymbol
)
_parameter
=
parameter
End
Sub
Public
ReadOnly
Property
ArgumentKind
As
ArgumentKind
Implements
IArgument
.
ArgumentKind
Get
Return
_kind
End
Get
End
Property
Public
ReadOnly
Property
Parameter
As
IParameterSymbol
Implements
IArgument
.
Parameter
Get
Return
_parameter
End
Get
End
Property
Public
ReadOnly
Property
Value
As
IExpression
Implements
IArgument
.
Value
Get
Return
Me
.
_value
End
Get
End
Property
Public
ReadOnly
Property
InConversion
As
IExpression
Implements
IArgument
.
InConversion
Get
Return
Nothing
End
Get
End
Property
Public
ReadOnly
Property
OutConversion
As
IExpression
Implements
IArgument
.
OutConversion
Get
Return
Nothing
End
Get
End
Property
Public
ReadOnly
Property
IsInvalid
As
Boolean
Implements
IOperation
.
IsInvalid
Get
Return
Me
.
Parameter
Is
Nothing
OrElse
Me
.
Value
.
IsInvalid
...
...
@@ -446,65 +422,82 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
Me
.
Value
.
Syntax
End
Get
End
Property
Public
MustOverride
ReadOnly
Property
ArgumentKind
As
ArgumentKind
Implements
IArgument
.
ArgumentKind
Public
MustOverride
ReadOnly
Property
Value
As
IExpression
Implements
IArgument
.
Value
Public
MustOverride
ReadOnly
Property
InConversion
As
IExpression
Implements
IArgument
.
InConversion
Public
MustOverride
ReadOnly
Property
OutConversion
As
IExpression
Implements
IArgument
.
OutConversion
End
Class
Private
Class
ByRef
Argument
I
mplements
IArgument
Private
Class
Argument
I
nherits
ArgumentBase
Private
ReadOnly
_
parameter
As
IParameterSymbol
Private
ReadOnly
_
argument
As
BoundByRefArgumentWithCopyBack
Private
ReadOnly
_
value
As
IExpression
Private
ReadOnly
_
kind
As
ArgumentKind
Public
Sub
New
(
parameter
As
IParameterSymbol
,
argument
As
BoundByRefArgumentWithCopyBack
)
_parameter
=
parameter
_argument
=
argument
Public
Sub
New
(
kind
As
ArgumentKind
,
parameter
As
IParameterSymbol
,
value
As
IExpression
)
MyBase
.
New
(
parameter
)
_value
=
value
_kind
=
kind
End
Sub
Public
ReadOnly
Property
InConversion
As
IExpression
Implements
IArgument
.
InConver
sion
Public
Overrides
ReadOnly
Property
Value
As
IExpres
sion
Get
Return
_argument
.
InConversion
Return
Me
.
_value
End
Get
End
Property
Public
ReadOnly
Property
ArgumentKind
As
ArgumentKind
Implements
IArgument
.
ArgumentKind
Public
Overrides
ReadOnly
Property
InConversion
As
IExpression
Get
' Do the VB bound trees encode named arguments?
Return
ArgumentKind
.
Positional
Return
Nothing
End
Get
End
Property
Public
ReadOnly
Property
OutConversion
As
IExpression
Implements
IArgument
.
OutConver
sion
Public
Overrides
ReadOnly
Property
OutConversion
As
IExpres
sion
Get
Return
_argument
.
OutConversion
Return
Nothing
End
Get
End
Property
Public
ReadOnly
Property
Parameter
As
IParameterSymbol
Implements
IArgument
.
Parameter
Public
Overrides
ReadOnly
Property
ArgumentKind
As
ArgumentKind
Get
Return
_
parameter
Return
_
kind
End
Get
End
Property
End
Class
Private
Class
ByRefArgument
Inherits
ArgumentBase
Public
ReadOnly
Property
Value
As
IExpression
Implements
IArgument
.
Value
Private
ReadOnly
_argument
As
BoundByRefArgumentWithCopyBack
Public
Sub
New
(
parameter
As
IParameterSymbol
,
argument
As
BoundByRefArgumentWithCopyBack
)
MyBase
.
New
(
parameter
)
_argument
=
argument
End
Sub
Public
Overrides
ReadOnly
Property
ArgumentKind
As
ArgumentKind
Get
Return
_argument
.
OriginalArgument
' Do the VB bound trees encode named arguments?
Return
ArgumentKind
.
Positional
End
Get
End
Property
Public
ReadOnly
Property
IsInvalid
As
Boolean
Implements
IOperation
.
IsInvalid
Public
Overrides
ReadOnly
Property
InConversion
As
IExpression
Get
Return
Me
.
Parameter
Is
Nothing
OrElse
Me
.
Value
.
IsInvalid
Return
_argument
.
InConversion
End
Get
End
Property
Public
ReadOnly
Property
Kind
As
OperationKind
Implements
IOperation
.
Kind
Public
Overrides
ReadOnly
Property
OutConversion
As
IExpression
Get
Return
OperationKind
.
Argument
Return
_argument
.
OutConversion
End
Get
End
Property
Public
ReadOnly
Property
Syntax
As
SyntaxNode
Implements
IOperation
.
Syntax
Public
Overrides
ReadOnly
Property
Value
As
IExpression
Get
Return
Me
.
Value
.
Syntax
Return
_argument
.
OriginalArgument
End
Get
End
Property
End
Class
...
...
@@ -1014,7 +1007,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial
Class
BoundObjectCreationExpression
Implements
IObjectCreationExpression
Private
Shared
MemberInitializersMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundObjectCreationExpression
,
IMemberInitializer
()
)
Private
Shared
ReadOnly
s_memberInitializersMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundObjectCreationExpression
,
Object
)
Private
Function
IArgumentMatchingParameter
(
parameter
As
IParameterSymbol
)
As
IArgument
Implements
IObjectCreationExpression
.
ArgumentMatchingParameter
Return
BoundCall
.
ArgumentMatchingParameter
(
Me
.
Arguments
,
parameter
,
Me
.
ConstructorOpt
.
Parameters
)
...
...
@@ -1034,31 +1027,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private
ReadOnly
Property
IMemberInitializers
As
ImmutableArray
(
Of
IMemberInitializer
)
Implements
IObjectCreationExpression
.
MemberInitializers
Get
Dim
initializer
=
MemberInitializersMappings
.
GetValue
(
Me
,
Function
(
objCreationStmt
)
Dim
objInitializerExp
As
BoundObjectInitializerExpressionBase
=
Me
.
InitializerOpt
If
objInitializerExp
IsNot
Nothing
Then
Dim
builder
=
ArrayBuilder
(
Of
IMemberInitializer
).
GetInstance
(
objInitializerExp
.
Initializers
.
Length
)
For
Each
memberAssignment
In
objInitializerExp
.
Initializers
Dim
assignment
=
TryCast
(
memberAssignment
,
BoundAssignmentOperator
)
Dim
left
=
assignment
?
.
Left
If
left
IsNot
Nothing
Then
Select
Case
left
.
Kind
Case
BoundKind
.
FieldAccess
builder
.
Add
(
New
FieldInitializer
(
assignment
.
Syntax
,
DirectCast
(
left
,
BoundFieldAccess
).
FieldSymbol
,
assignment
.
Right
))
Case
BoundKind
.
PropertyAccess
builder
.
Add
(
New
PropertyInitializer
(
assignment
.
Syntax
,
DirectCast
(
left
,
BoundPropertyAccess
).
PropertySymbol
.
SetMethod
,
assignment
.
Right
))
End
Select
End
If
Next
Return
builder
.
ToArrayAndFree
()
End
If
Return
New
IMemberInitializer
()
{}
End
Function
)
Dim
immBuilder
=
ArrayBuilder
(
Of
IMemberInitializer
).
GetInstance
(
initializer
.
Length
)
immBuilder
.
AddRange
(
initializer
)
Return
immBuilder
.
ToImmutableAndFree
()
Dim
initializer
=
s_memberInitializersMappings
.
GetValue
(
Me
,
Function
(
objectCreationStatement
)
Dim
objectInitializerExpression
As
BoundObjectInitializerExpressionBase
=
Me
.
InitializerOpt
If
objectInitializerExpression
IsNot
Nothing
Then
Dim
builder
=
ArrayBuilder
(
Of
IMemberInitializer
).
GetInstance
(
objectInitializerExpression
.
Initializers
.
Length
)
For
Each
memberAssignment
In
objectInitializerExpression
.
Initializers
Dim
assignment
=
TryCast
(
memberAssignment
,
BoundAssignmentOperator
)
Dim
left
=
assignment
?
.
Left
If
left
IsNot
Nothing
Then
Select
Case
left
.
Kind
Case
BoundKind
.
FieldAccess
builder
.
Add
(
New
FieldInitializer
(
assignment
.
Syntax
,
DirectCast
(
left
,
BoundFieldAccess
).
FieldSymbol
,
assignment
.
Right
))
Case
BoundKind
.
PropertyAccess
builder
.
Add
(
New
PropertyInitializer
(
assignment
.
Syntax
,
DirectCast
(
left
,
BoundPropertyAccess
).
PropertySymbol
.
SetMethod
,
assignment
.
Right
))
End
Select
End
If
Next
Return
builder
.
ToImmutableAndFree
()
End
If
Return
ImmutableArray
(
Of
IMemberInitializer
).
Empty
End
Function
)
Return
DirectCast
(
initializer
,
ImmutableArray
(
Of
IMemberInitializer
))
End
Get
End
Property
...
...
src/Compilers/VisualBasic/Portable/BoundTree/Statement.vb
浏览文件 @
98d7a9c0
...
...
@@ -90,15 +90,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Get
End
Property
Private
Shared
CaseElseMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundCaseStatement
,
ICaseClause
)
Private
Shared
CaseElseMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundCaseStatement
,
Object
)
Private
ReadOnly
Property
IClauses
As
ImmutableArray
(
Of
ICaseClause
)
Implements
ICase
.
Clauses
Get
' `CaseElseClauseSyntax` is bound to `BoundCaseStatement` with an empty list of case clauses,
' so we explicitly create an IOperation node for Case-Else clause to differentiate it from Case clause.
If
Me
.
CaseStatement
.
CaseClauses
.
IsEmpty
AndAlso
Me
.
CaseStatement
.
Syntax
.
Kind
()
=
SyntaxKind
.
CaseElseStatement
Then
Dim
caseElse
=
CaseElseMappings
.
GetValue
(
Me
.
CaseStatement
,
Function
(
stmt
)
New
CaseElse
(
stmt
))
Return
ImmutableArray
.
Create
(
caseElse
)
Dim
caseElse
=
CaseElseMappings
.
GetValue
(
Me
.
CaseStatement
,
Function
(
caseStatement
)
ImmutableArray
.
Create
(
Of
ICaseClause
)(
New
CaseElse
(
caseStatement
)
))
Return
DirectCast
(
caseElse
,
ImmutableArray
(
Of
ICaseClause
)
)
End
If
Return
Me
.
CaseStatement
.
CaseClauses
.
As
(
Of
ICaseClause
)()
...
...
@@ -376,11 +376,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial
Class
BoundForToStatement
Implements
IForLoopStatement
Private
Shared
L
oopBottomMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
Object
)
Private
Shared
ReadOnly
s_l
oopBottomMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
Object
)
Private
ReadOnly
Property
IAtLoopBottom
As
ImmutableArray
(
Of
IStatement
)
Implements
IForLoopStatement
.
AtLoopBottom
Get
Dim
result
=
L
oopBottomMappings
.
GetValue
(
Dim
result
=
s_l
oopBottomMappings
.
GetValue
(
Me
,
Function
(
BoundFor
)
Dim
statements
As
ArrayBuilder
(
Of
IStatement
)
=
ArrayBuilder
(
Of
IStatement
).
GetInstance
()
...
...
@@ -412,11 +412,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Get
End
Property
Private
Shared
L
oopTopMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
Object
)
Private
Shared
ReadOnly
s_l
oopTopMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
Object
)
Private
ReadOnly
Property
IBefore
As
ImmutableArray
(
Of
IStatement
)
Implements
IForLoopStatement
.
Before
Get
Dim
result
=
L
oopTopMappings
.
GetValue
(
Dim
result
=
s_l
oopTopMappings
.
GetValue
(
Me
,
Function
(
BoundFor
)
Dim
statements
As
ArrayBuilder
(
Of
IStatement
)
=
ArrayBuilder
(
Of
IStatement
).
GetInstance
()
...
...
@@ -450,11 +450,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Get
End
Property
Private
Shared
L
oopConditionMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
IExpression
)
Private
Shared
ReadOnly
s_l
oopConditionMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundForToStatement
,
IExpression
)
Private
ReadOnly
Property
ICondition
As
IExpression
Implements
IForWhileUntilLoopStatement
.
Condition
Get
Return
L
oopConditionMappings
.
GetValue
(
Return
s_l
oopConditionMappings
.
GetValue
(
Me
,
Function
(
BoundFor
)
Dim
limitValue
As
IExpression
=
If
(
BoundFor
.
LimitValue
.
IsConstant
,
DirectCast
(
BoundFor
.
LimitValue
,
IExpression
),
New
Temporary
(
SyntheticLocalKind
.
ForLoopLimitValue
,
BoundFor
,
BoundFor
.
LimitValue
))
...
...
@@ -774,29 +774,27 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial
Class
BoundDimStatement
Implements
IVariableDeclarationStatement
Private
Shared
VariablesMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundDimStatement
,
IVariable
()
)
Private
Shared
ReadOnly
s_variablesMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundDimStatement
,
Object
)
Private
ReadOnly
Property
IVariables
As
ImmutableArray
(
Of
IVariable
)
Implements
IVariableDeclarationStatement
.
Variables
Get
Dim
variables
=
VariablesMappings
.
GetValue
(
Me
,
Function
(
dimStm
t
)
Dim
arrB
uilder
=
ArrayBuilder
(
Of
IVariable
).
GetInstance
()
For
Each
base
In
dimStm
t
.
LocalDeclarations
If
base
.
Kind
=
BoundKind
.
LocalDeclaration
Then
Dim
decl
=
DirectCast
(
base
,
BoundLocalDeclaration
)
arrBuilder
.
Add
(
New
VariableDeclaration
(
decl
.
LocalSymbol
,
decl
.
InitializerOpt
,
decl
.
Syntax
))
ElseIf
base
.
Kind
=
BoundKind
.
AsNewLocalDeclarations
Then
Dim
asNewDecl
s
=
DirectCast
(
base
,
BoundAsNewLocalDeclarations
)
For
Each
asNewDecl
In
asNewDecl
s
.
LocalDeclarations
arrBuilder
.
Add
(
New
VariableDeclaration
(
asNewDecl
.
LocalSymbol
,
asNewDecls
.
Initializer
,
asNewDecl
.
Syntax
))
Next
End
If
Next
Return
arrBuilder
.
ToArray
AndFree
()
End
Function
Dim
variables
=
s_variablesMappings
.
GetValue
(
Me
,
Function
(
dimStatemen
t
)
Dim
b
uilder
=
ArrayBuilder
(
Of
IVariable
).
GetInstance
()
For
Each
base
In
dimStatemen
t
.
LocalDeclarations
If
base
.
Kind
=
BoundKind
.
LocalDeclaration
Then
Dim
declaration
=
DirectCast
(
base
,
BoundLocalDeclaration
)
builder
.
Add
(
New
VariableDeclaration
(
declaration
.
LocalSymbol
,
declaration
.
InitializerOpt
,
declaration
.
Syntax
))
ElseIf
base
.
Kind
=
BoundKind
.
AsNewLocalDeclarations
Then
Dim
asNewDeclaration
s
=
DirectCast
(
base
,
BoundAsNewLocalDeclarations
)
For
Each
asNewDeclaration
In
asNewDeclaration
s
.
LocalDeclarations
builder
.
Add
(
New
VariableDeclaration
(
asNewDeclaration
.
LocalSymbol
,
asNewDeclarations
.
Initializer
,
asNewDeclaration
.
Syntax
))
Next
End
If
Next
Return
builder
.
ToImmutable
AndFree
()
End
Function
)
Dim
immBuilder
=
ArrayBuilder
(
Of
IVariable
).
GetInstance
(
variables
.
Length
)
immBuilder
.
AddRange
(
variables
)
Return
immBuilder
.
ToImmutableAndFree
()
Return
DirectCast
(
variables
,
ImmutableArray
(
Of
IVariable
))
End
Get
End
Property
...
...
@@ -959,11 +957,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
Get
End
Property
Private
Shared
V
ariablesMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundUsingStatement
,
Variables
)
Private
Shared
ReadOnly
s_v
ariablesMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundUsingStatement
,
Variables
)
Private
ReadOnly
Property
IVariables
As
IVariableDeclarationStatement
Implements
IUsingWithDeclarationStatement
.
Variables
Get
Return
V
ariablesMappings
.
GetValue
(
Return
s_v
ariablesMappings
.
GetValue
(
Me
,
Function
(
BoundUsing
)
Return
New
Variables
(
BoundUsing
.
ResourceList
.
As
(
Of
IVariable
))
...
...
@@ -1033,7 +1031,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Partial
Class
BoundAddRemoveHandlerStatement
Implements
IExpressionStatement
Protected
Shared
E
xpressionsMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundAddRemoveHandlerStatement
,
IEventAssignmentExpression
)
Protected
Shared
ReadOnly
s_e
xpressionsMappings
As
New
System
.
Runtime
.
CompilerServices
.
ConditionalWeakTable
(
Of
BoundAddRemoveHandlerStatement
,
IEventAssignmentExpression
)
Protected
Overrides
Function
StatementKind
()
As
OperationKind
Return
OperationKind
.
ExpressionStatement
...
...
@@ -1122,9 +1120,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Protected
Overrides
ReadOnly
Property
IExpression
As
IExpression
Get
Return
E
xpressionsMappings
.
GetValue
(
Me
,
Function
(
statement
)
Return
New
EventAssignmentExpression
(
statement
,
True
)
End
Function
)
Return
s_e
xpressionsMappings
.
GetValue
(
Me
,
Function
(
statement
)
Return
New
EventAssignmentExpression
(
statement
,
True
)
End
Function
)
End
Get
End
Property
End
Class
...
...
@@ -1133,9 +1131,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Protected
Overrides
ReadOnly
Property
IExpression
As
IExpression
Get
Return
E
xpressionsMappings
.
GetValue
(
Me
,
Function
(
statement
)
Return
New
EventAssignmentExpression
(
statement
,
False
)
End
Function
)
Return
s_e
xpressionsMappings
.
GetValue
(
Me
,
Function
(
statement
)
Return
New
EventAssignmentExpression
(
statement
,
False
)
End
Function
)
End
Get
End
Property
End
Class
...
...
src/Compilers/VisualBasic/Test/Semantic/Diagnostics/OperationAnalyzerTests.vb
浏览文件 @
98d7a9c0
...
...
@@ -811,6 +811,9 @@ Class C
Dim
f3
=
New
Foo
With
{.
Prop1
=
Nothing
}
Dim
f4
=
New
Foo
With
{.
Field
=
10
,
.
Prop1
=
Nothing
}
Dim
f5
=
New
Foo
With
{.
Prop2
=
New
Bar
()
With
{.
Field
=
True
}}
Dim
e1
=
New
Foo
()
With
{.
Prop1
=
10
}
Dim
e2
=
New
Foo
With
{
10
}
End
Sub
End
Class
]]
>
...
...
@@ -818,14 +821,15 @@ End Class
</
compilation
>
Dim
comp
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
source
)
comp
.
VerifyDiagnostics
()
comp
.
VerifyDiagnostics
(
Diagnostic
(
ERRID
.
ERR_ExpectedQualifiedNameInInit
,
""
).
WithLocation
(
20
,
32
)
)
comp
.
VerifyAnalyzerDiagnostics
({
New
MemberInitializerTestAnalyzer
},
Nothing
,
Nothing
,
False
,
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
".Field = 10"
).
WithLocation
(
14
,
34
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
".Prop1 = Nothing"
).
WithLocation
(
15
,
32
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
".Field = 10"
).
WithLocation
(
16
,
32
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
".Prop1 = Nothing"
).
WithLocation
(
16
,
45
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
".Prop2 = New Bar() With {.Field = True}"
).
WithLocation
(
17
,
32
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
".Field = True"
).
WithLocation
(
17
,
57
))
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUseFieldInitiliazerDescriptor
.
Id
,
".Field = True"
).
WithLocation
(
17
,
57
),
Diagnostic
(
MemberInitializerTestAnalyzer
.
DoNotUsePropertyInitializerDescriptor
.
Id
,
".Prop1 = 10"
).
WithLocation
(
19
,
34
))
End
Sub
<
Fact
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录