Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
677878c1
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,发现更多精彩内容 >>
提交
677878c1
编写于
10月 31, 2017
作者:
M
Manish Vasani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address PR feedback
上级
6fede951
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
2 deletion
+61
-2
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/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
浏览文件 @
677878c1
...
@@ -193,7 +193,7 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
...
@@ -193,7 +193,7 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
SyntaxNode
syntax
=
value
.
Syntax
?.
Parent
??
expression
.
Syntax
;
SyntaxNode
syntax
=
value
.
Syntax
?.
Parent
??
expression
.
Syntax
;
ITypeSymbol
type
=
target
.
Type
;
ITypeSymbol
type
=
target
.
Type
;
Optional
<
object
>
constantValue
=
value
.
ConstantValue
;
Optional
<
object
>
constantValue
=
value
.
ConstantValue
;
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
false
);
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
expression
.
WasCompilerGenerated
);
builder
.
Add
(
assignment
);
builder
.
Add
(
assignment
);
}
}
...
...
src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs
浏览文件 @
677878c1
...
@@ -1610,6 +1610,65 @@ public static void Main()
...
@@ -1610,6 +1610,65 @@ public static void Main()
}"
,
additionalRefs
:
new
[]
{
SystemCoreRef
}).
VerifyDiagnostics
();
}"
,
additionalRefs
:
new
[]
{
SystemCoreRef
}).
VerifyDiagnostics
();
}
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
)]
[
Fact
]
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"
#
region
"Utility methods"
private
void
AssertCannotConstruct
(
ISymbol
type
)
private
void
AssertCannotConstruct
(
ISymbol
type
)
...
...
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
浏览文件 @
677878c1
...
@@ -207,7 +207,7 @@ Namespace Microsoft.CodeAnalysis.Operations
...
@@ -207,7 +207,7 @@ Namespace Microsoft.CodeAnalysis.Operations
Dim
syntax
As
SyntaxNode
=
If
(
value
.
Syntax
?
.
Parent
,
expression
.
Syntax
)
Dim
syntax
As
SyntaxNode
=
If
(
value
.
Syntax
?
.
Parent
,
expression
.
Syntax
)
Dim
type
As
ITypeSymbol
=
target
.
Type
Dim
type
As
ITypeSymbol
=
target
.
Type
Dim
constantValue
As
[
Optional
]
(
Of
Object
)
=
value
.
ConstantValue
Dim
constantValue
As
[
Optional
]
(
Of
Object
)
=
value
.
ConstantValue
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
=
False
)
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
:
=
expression
.
WasCompilerGenerated
)
builder
.
Add
(
assignment
)
builder
.
Add
(
assignment
)
Next
i
Next
i
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录