Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
46681277
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,发现更多精彩内容 >>
未验证
提交
46681277
编写于
11月 02, 2017
作者:
M
Manish Vasani
提交者:
GitHub
11月 02, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22867 from mavasani/Issue22588
Fix IsImplicit for anonymous type field assignments
上级
0f1a1956
dac27dc0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
6 deletion
+65
-6
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
...arp/Portable/Operations/CSharpOperationFactory_Methods.cs
+1
-1
src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs
...Sharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs
+59
-0
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
...ortable/Operations/VisualBasicOperationFactory_Methods.vb
+1
-1
src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests.vb
...s/VisualBasic/Test/Semantic/IOperation/IOperationTests.vb
+1
-1
src/Compilers/VisualBasic/Test/Semantic/Semantics/AnonymousTypesTests.vb
...isualBasic/Test/Semantic/Semantics/AnonymousTypesTests.vb
+3
-3
未找到文件。
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
浏览文件 @
46681277
...
...
@@ -199,7 +199,7 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
SyntaxNode
syntax
=
value
.
Syntax
?.
Parent
??
expression
.
Syntax
;
ITypeSymbol
type
=
target
.
Type
;
Optional
<
object
>
constantValue
=
value
.
ConstantValue
;
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
value
.
IsImplicit
);
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
expression
.
WasCompilerGenerated
);
builder
.
Add
(
assignment
);
}
...
...
src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs
浏览文件 @
46681277
...
...
@@ -1630,6 +1630,65 @@ public static void Main()
}"
,
additionalRefs
:
new
[]
{
SystemCoreRef
}).
VerifyDiagnostics
();
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
)]
[
Fact
,
WorkItem
(
22588
,
"https://github.com/dotnet/roslyn/issues/22588"
)]
public
void
AnonymousTypeSymbols_ErrorCases
()
{
string
source
=
@"
class ClassA
{
static void Test1(int x)
{
var obj = /*<bind>*/new { f1 = null, f2 = M, f3 = default }/*</bind>*/;
}
static void M()
{
}
}
"
;
string
expectedOperationTree
=
@"
IAnonymousObjectCreationOperation (OperationKind.AnonymousObjectCreation, Type: <anonymous type: error f1, error f2, error f3>, IsInvalid) (Syntax: 'new { f1 = ... = default }')
Initializers(3):
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, Constant: null, IsInvalid) (Syntax: 'f1 = null')
Left:
IPropertyReferenceOperation: error <anonymous type: error f1, error f2, error f3>.f1 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f1')
Instance Receiver:
null
Right:
ILiteralOperation (OperationKind.Literal, Type: null, Constant: null, IsInvalid) (Syntax: 'null')
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, IsInvalid) (Syntax: 'f2 = M')
Left:
IPropertyReferenceOperation: error <anonymous type: error f1, error f2, error f3>.f2 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f2')
Instance Receiver:
null
Right:
IOperation: (OperationKind.None, Type: null, IsInvalid) (Syntax: 'M')
Children(1):
IInstanceReferenceOperation (OperationKind.InstanceReference, Type: ClassA, IsInvalid, IsImplicit) (Syntax: 'M')
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, IsInvalid) (Syntax: 'f3 = default')
Left:
IPropertyReferenceOperation: error <anonymous type: error f1, error f2, error f3>.f3 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f3')
Instance Receiver:
null
Right:
IDefaultValueOperation (OperationKind.DefaultValue, Type: null, IsInvalid) (Syntax: 'default')
"
;
var
expectedDiagnostics
=
new
DiagnosticDescription
[]
{
// file.cs(6,35): error CS0828: Cannot assign '<null>' to anonymous type property
// var obj = /*<bind>*/new { f1 = null, f2 = M, f3 = default }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_AnonymousTypePropertyAssignedBadValue
,
"f1 = null"
).
WithArguments
(
"<null>"
).
WithLocation
(
6
,
35
),
// file.cs(6,46): error CS0828: Cannot assign 'method group' to anonymous type property
// var obj = /*<bind>*/new { f1 = null, f2 = M, f3 = default }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_AnonymousTypePropertyAssignedBadValue
,
"f2 = M"
).
WithArguments
(
"method group"
).
WithLocation
(
6
,
46
),
// file.cs(6,54): error CS0828: Cannot assign 'default' to anonymous type property
// var obj = /*<bind>*/new { f1 = null, f2 = M, f3 = default }/*</bind>*/;
Diagnostic
(
ErrorCode
.
ERR_AnonymousTypePropertyAssignedBadValue
,
"f3 = default"
).
WithArguments
(
"default"
).
WithLocation
(
6
,
54
)
};
VerifyOperationTreeAndDiagnosticsForTest
<
AnonymousObjectCreationExpressionSyntax
>(
source
,
expectedOperationTree
,
expectedDiagnostics
);
}
#
region
"Utility methods"
private
void
AssertCannotConstruct
(
ISymbol
type
)
...
...
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
浏览文件 @
46681277
...
...
@@ -207,7 +207,7 @@ Namespace Microsoft.CodeAnalysis.Operations
Dim
syntax
As
SyntaxNode
=
If
(
value
.
Syntax
?
.
Parent
,
expression
.
Syntax
)
Dim
type
As
ITypeSymbol
=
target
.
Type
Dim
constantValue
As
[
Optional
]
(
Of
Object
)
=
value
.
ConstantValue
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
=
value
.
IsImplicit
)
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
=
expression
.
WasCompilerGenerated
)
builder
.
Add
(
assignment
)
Next
i
...
...
src/Compilers/VisualBasic/Test/Semantic/IOperation/IOperationTests.vb
浏览文件 @
46681277
...
...
@@ -439,7 +439,7 @@ End Module]]>.Value
Dim
expectedOperationTree
=
<
!
[
CDATA
[
IAnonymousObjectCreationOperation
(
OperationKind
.
AnonymousObjectCreation
,
Type
:
<
anonymous
type
:
Key
a
As
?
>
,
IsInvalid
)
(
Syntax
:
'New With {K ... essOf c1.S}')
Initializers
(
1
):
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
,
IsImplicit
)
(
Syntax
:
'Key .a = AddressOf c1.S')
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
)
(
Syntax
:
'Key .a = AddressOf c1.S')
Left
:
IPropertyReferenceOperation
:
ReadOnly
Property
<
anonymous
type
:
Key
a
As
?
>
.
a
As
?
(
OperationKind
.
PropertyReference
,
Type
:
?
)
(
Syntax
:
'a')
Instance
Receiver
:
...
...
src/Compilers/VisualBasic/Test/Semantic/Semantics/AnonymousTypesTests.vb
浏览文件 @
46681277
...
...
@@ -474,7 +474,7 @@ End Module]]>.Value
Dim
expectedOperationTree
=
<
!
[
CDATA
[
IAnonymousObjectCreationOperation
(
OperationKind
.
AnonymousObjectCreation
,
Type
:
<
anonymous
type
:
a
As
?
>
,
IsInvalid
)
(
Syntax
:
'New With {. ... SubName()}')
Initializers
(
1
):
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
,
IsImplicit
)
(
Syntax
:
'.a = SubName()')
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
)
(
Syntax
:
'.a = SubName()')
Left
:
IPropertyReferenceOperation
:
Property
<
anonymous
type
:
a
As
?
>
.
a
As
?
(
OperationKind
.
PropertyReference
,
Type
:
?
)
(
Syntax
:
'a')
Instance
Receiver
:
...
...
@@ -582,7 +582,7 @@ End Module]]>.Value
Dim
expectedOperationTree
=
<
!
[
CDATA
[
IAnonymousObjectCreationOperation
(
OperationKind
.
AnonymousObjectCreation
,
Type
:
<
anonymous
type
:
a
As
System
.
Object
>
)
(
Syntax
:
'New With {.a = Nothing}')
Initializers
(
1
):
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
System
.
Object
,
Constant
:
null
,
IsImplicit
)
(
Syntax
:
'.a = Nothing')
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
System
.
Object
,
Constant
:
null
)
(
Syntax
:
'.a = Nothing')
Left
:
IPropertyReferenceOperation
:
Property
<
anonymous
type
:
a
As
System
.
Object
>
.
a
As
System
.
Object
(
OperationKind
.
PropertyReference
,
Type
:
System
.
Object
)
(
Syntax
:
'a')
Instance
Receiver
:
...
...
@@ -917,7 +917,7 @@ End Module]]>.Value
Dim
expectedOperationTree
=
<
!
[
CDATA
[
IAnonymousObjectCreationOperation
(
OperationKind
.
AnonymousObjectCreation
,
Type
:
<
anonymous
type
:
Key
a
As
?
>
,
IsInvalid
)
(
Syntax
:
'New With {K ... ddressOf S}')
Initializers
(
1
):
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
,
IsImplicit
)
(
Syntax
:
'Key .a = AddressOf S')
ISimpleAssignmentOperation
(
OperationKind
.
SimpleAssignment
,
Type
:
?
,
IsInvalid
)
(
Syntax
:
'Key .a = AddressOf S')
Left
:
IPropertyReferenceOperation
:
ReadOnly
Property
<
anonymous
type
:
Key
a
As
?
>
.
a
As
?
(
OperationKind
.
PropertyReference
,
Type
:
?
)
(
Syntax
:
'a')
Instance
Receiver
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录