Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2851759c
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,发现更多精彩内容 >>
未验证
提交
2851759c
编写于
11月 26, 2018
作者:
F
Fredric Silberberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disallow null coalescing assignment in expression trees.
上级
e87464c0
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
108 addition
and
2 deletion
+108
-2
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+10
-1
src/Compilers/CSharp/Portable/CSharpResources.resx
src/Compilers/CSharp/Portable/CSharpResources.resx
+3
-0
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+2
-1
src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
...harp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
+10
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
...Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+5
-0
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
...Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+5
-0
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
...Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
+18
-0
未找到文件。
src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
浏览文件 @
2851759c
...
...
@@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.CSharp {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "1
5
.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "1
6
.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CSharpResources {
...
...
@@ -4425,6 +4425,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to An expression tree may not contain a null coalescing assignment.
/// </summary>
internal static string ERR_ExpressionTreeCantContainNullCoalescingAssignment {
get {
return ResourceManager.GetString("ERR_ExpressionTreeCantContainNullCoalescingAssignment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Expression tree cannot contain value of ref struct or restricted type '{0}'..
/// </summary>
...
...
src/Compilers/CSharp/Portable/CSharpResources.resx
浏览文件 @
2851759c
...
...
@@ -5635,4 +5635,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data
name=
"ERR_ElseCannotStartStatement"
xml:space=
"preserve"
>
<value>
'else' cannot start a statement.
</value>
</data>
<data
name=
"ERR_ExpressionTreeCantContainNullCoalescingAssignment"
xml:space=
"preserve"
>
<value>
An expression tree may not contain a null coalescing assignment
</value>
</data>
</root>
\ No newline at end of file
src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
浏览文件 @
2851759c
...
...
@@ -1636,7 +1636,8 @@ internal enum ErrorCode
WRN_CantInferNullabilityOfMethodTypeArgs
=
8638
,
WRN_NoBestNullabilityArrayElements
=
8639
,
ERR_ExpressionTreeCantContainRefStruct
=
8640
,
ERR_ElseCannotStartStatement
=
8641
ERR_ElseCannotStartStatement
=
8641
,
ERR_ExpressionTreeCantContainNullCoalescingAssignment
=
8642
#
endregion
diagnostics
introduced
for
C
#
8.0
...
...
src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
浏览文件 @
2851759c
...
...
@@ -614,6 +614,16 @@ public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperato
return
base
.
VisitNullCoalescingOperator
(
node
);
}
public
override
BoundNode
VisitNullCoalescingAssignmentOperator
(
BoundNullCoalescingAssignmentOperator
node
)
{
if
(
_inExpressionLambda
)
{
Error
(
ErrorCode
.
ERR_ExpressionTreeCantContainNullCoalescingAssignment
,
node
);
}
return
base
.
VisitNullCoalescingAssignmentOperator
(
node
);
}
public
override
BoundNode
VisitDynamicInvocation
(
BoundDynamicInvocation
node
)
{
if
(
_inExpressionLambda
)
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target
state=
"new"
>
The given expression cannot be used in a fixed statement
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainNullCoalescingAssignment"
>
<source>
An expression tree may not contain a null coalescing assignment
</source>
<target
state=
"new"
>
An expression tree may not contain a null coalescing assignment
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainRefStruct"
>
<source>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</source>
<target
state=
"new"
>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target
state=
"new"
>
The given expression cannot be used in a fixed statement
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainNullCoalescingAssignment"
>
<source>
An expression tree may not contain a null coalescing assignment
</source>
<target
state=
"new"
>
An expression tree may not contain a null coalescing assignment
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainRefStruct"
>
<source>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</source>
<target
state=
"new"
>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target state="new">The given expression cannot be used in a fixed statement</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainNullCoalescingAssignment">
<source>An expression tree may not contain a null coalescing assignment</source>
<target state="new">An expression tree may not contain a null coalescing assignment</target>
<note />
</trans-unit>
<trans-unit id="ERR_ExpressionTreeCantContainRefStruct">
<source>Expression tree cannot contain value of ref struct or restricted type '{0}'.</source>
<target state="new">Expression tree cannot contain value of ref struct or restricted type '{0}'.</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target
state=
"new"
>
The given expression cannot be used in a fixed statement
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainNullCoalescingAssignment"
>
<source>
An expression tree may not contain a null coalescing assignment
</source>
<target
state=
"new"
>
An expression tree may not contain a null coalescing assignment
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainRefStruct"
>
<source>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</source>
<target
state=
"new"
>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</target>
...
...
src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
浏览文件 @
2851759c
...
...
@@ -62,6 +62,11 @@
<target
state=
"new"
>
The given expression cannot be used in a fixed statement
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainNullCoalescingAssignment"
>
<source>
An expression tree may not contain a null coalescing assignment
</source>
<target
state=
"new"
>
An expression tree may not contain a null coalescing assignment
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"ERR_ExpressionTreeCantContainRefStruct"
>
<source>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</source>
<target
state=
"new"
>
Expression tree cannot contain value of ref struct or restricted type '{0}'.
</target>
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
浏览文件 @
2851759c
...
...
@@ -2351,5 +2351,23 @@ void M()
// Span<byte>? s2 = null;
Diagnostic
(
ErrorCode
.
ERR_BadTypeArgument
,
"Span<byte>?"
).
WithArguments
(
"System.Span<byte>"
).
WithLocation
(
9
,
9
));
}
[
Fact
]
[
WorkItem
(
32138
,
"https://github.com/dotnet/roslyn/issues/31238"
)]
public
void
ExpressionTreeNotAllowed
()
{
CreateCompilation
(
@"
using System;
using System.Linq.Expressions;
public class C {
public void M() {
String x = null;
Expression<Func<string>> e0 = () => x ??= null;
}
}"
).
VerifyDiagnostics
(
// (7,45): error CS8642: An expression tree may not contain a null coalescing assignment
// Expression<Func<string>> e0 = () => x ??= null;
Diagnostic
(
ErrorCode
.
ERR_ExpressionTreeCantContainNullCoalescingAssignment
,
"x ??= null"
).
WithLocation
(
7
,
45
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录