diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
index 52adc30fe8a53ee1bc422ff5050b2372d8c70f23..db7454443320bebcb63d83bcfb949832b20b061d 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
@@ -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", "15.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class CSharpResources {
@@ -4425,6 +4425,15 @@ internal class CSharpResources {
}
}
+ ///
+ /// Looks up a localized string similar to An expression tree may not contain a null coalescing assignment.
+ ///
+ internal static string ERR_ExpressionTreeCantContainNullCoalescingAssignment {
+ get {
+ return ResourceManager.GetString("ERR_ExpressionTreeCantContainNullCoalescingAssignment", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Expression tree cannot contain value of ref struct or restricted type '{0}'..
///
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index b51b7c80b5db9352ddf177f3e3997c4a6380a870..f1c2a94a0ec54f781f6ae40823bd79af3774ffb3 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -5635,4 +5635,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
'else' cannot start a statement.
+
+ An expression tree may not contain a null coalescing assignment
+
\ No newline at end of file
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
index b2cd9e198b0fc4a2f5d7fb68940324fd9e857920..c3a7b51ad4e8ebcbb9b21b7f9cade9773ae9b0d8 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
@@ -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
diff --git a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
index 5318f2561c7c348926342fb0f3d6f1dd126733e6..b5749105ffd23c021163cfed32a09e99d2b39de5 100644
--- a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
+++ b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
@@ -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)
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index 4c37a7978d94f8a5a31df9f5234fc4329b1b1a20..50b905a808ba73bc92e5a41949e629345f1d9ede 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
index de5b43d9022c7cfccd964cf58f0d2f75a8074e50..20591719507d5c5938675c870321504a16b2250a 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
index 13a9c7e156bcbee43260b0d05ce1a415f04be373..a23c2fcd9d4827bda1195939609f12c2a27d7f3f 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
index 6e96040e0821a53a0cbdb5d8a30341e255379c6a..23861e4fd7810fa409d0ef27fb5aa0e2fc65f655 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
index 2362e575c803c787b8159eef779e6f6b87a2405d..8848fc114f0d426a8bd9365cde52d75768544315 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
index decef136ffa3cf976f02ad9ef0b86a2555b6f895..68b5e9f55f87f575b13d00d2541bd6f0d8fdf271 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
index 08f130cf5a17ce8b36a877d54c243152e0be438c..5d216143297fb27e732773c5a156e659a2d277c8 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
index 5dc50ddb1d7e52e8e0df1f3d39ecd4353be8213f..009233f4572f7c1d6a06690e797e408cfb38fe84 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
index fa4be4bc588795c646d0b3827b9cdfeed8e0ef89..a123e2c4389c8a51e2a4fbb34dd7b652082b4351 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
index ed30aba195836e8483e69f8e854b23bb69bdbe4e..a8aaa8e0f0a87ece010a19af37f580b5e7264466 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
index 2ee72e9d99478bf0fc0d7d24c320d6fda5cb6873..f8cc406b21e998f4e3229b8d48e702beb49015d1 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
index f04c17dc27022ebf01ac747449096705337d9fa4..50196a365e89e15b42dc9803cb86960fc8a915b6 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
index 648449a366e362426dd9c4c0d5949ad740187e9c..27bfbbc758277957c1efe83f034a04b03b3c5bc4 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@@ -62,6 +62,11 @@
The given expression cannot be used in a fixed statement
+
+ An expression tree may not contain a null coalescing assignment
+ An expression tree may not contain a null coalescing assignment
+
+ Expression tree cannot contain value of ref struct or restricted type '{0}'.Expression tree cannot contain value of ref struct or restricted type '{0}'.
diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
index 57559b4c40cc59f6fcf0fa9be667f49a69ebe2ce..ae890ec0fae87ddce6ce61adc5e2da815d50a921 100644
--- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenNullCoalescingAssignmentTests.cs
@@ -2351,5 +2351,23 @@ void M()
// Span? s2 = null;
Diagnostic(ErrorCode.ERR_BadTypeArgument, "Span?").WithArguments("System.Span").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> e0 = () => x ??= null;
+ }
+}").VerifyDiagnostics(
+ // (7,45): error CS8642: An expression tree may not contain a null coalescing assignment
+ // Expression> e0 = () => x ??= null;
+ Diagnostic(ErrorCode.ERR_ExpressionTreeCantContainNullCoalescingAssignment, "x ??= null").WithLocation(7, 45));
+ }
}
}