diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs index 07c57169ff8abf6bfdf03e16aa0b5edd77f4e24d..33f466bd9ffec92e51f9cd554db8f174899dc43a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs @@ -3521,6 +3521,10 @@ private BoundExpression BindConditionalOperator(ConditionalExpressionSyntax node diagnostics.Add(ErrorCode.ERR_RefConditionalNeedsTwoRefs, whenTrue.GetFirstToken().GetLocation()); } } + else + { + CheckFeatureAvailability(node, MessageID.IDS_FeatureRefConditional, diagnostics); + } BoundExpression condition = BindBooleanExpression(node.Condition, diagnostics); diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs index ff90d85491af95c82e755856e85a9d83124dba45..2010878cbe3e15b36e0e225f3fac21b7be89273c 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs +++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs @@ -10700,6 +10700,15 @@ internal class CSharpResources { } } + /// + /// Looks up a localized string similar to ref conditional expression. + /// + internal static string IDS_FeatureRefConditional { + get { + return ResourceManager.GetString("IDS_FeatureRefConditional", resourceCulture); + } + } + /// /// Looks up a localized string similar to ref extension methods. /// diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index a4e5cbf510350edaf152dc74932ce3f10e9d036d..b0d3343e7660d6de6e61f74c61e5087d918af1dd 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -4264,6 +4264,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ref structs + + ref conditional expression + Compilation (C#): diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 935a0f2d0495b96e7fc49dd4215e07a5c9086557..6d16f1c290da340ff041b659270f2ad5608316d8 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -145,6 +145,7 @@ internal enum MessageID IDS_FeatureRefExtensionMethods = MessageBase + 12728, IDS_StackAllocExpression = MessageBase + 12729, IDS_FeaturePrivateProtected = MessageBase + 12730, + IDS_FeatureRefConditional = MessageBase + 12731, } // Message IDs may refer to strings that need to be localized. @@ -192,6 +193,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) case MessageID.IDS_FeatureRefStructs: case MessageID.IDS_FeatureReadOnlyStructs: case MessageID.IDS_FeatureRefExtensionMethods: + case MessageID.IDS_FeatureRefConditional: return LanguageVersion.CSharp7_2; // C# 7.1 features. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 834382efc0165facc82fe9ef8753f9a75e18a93e..6374f21b666a117053d0e7b5a51f236f4439c034 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -8590,6 +8590,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index e8e91a80ca98307975d8d1f7e80ac194e55cffb4..9853e7756ac64d4f3e3459c23b1728dd4d88b017 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -8590,6 +8590,11 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 34acd3bc237e4ac433bf437eeaaacc615b6ff45a..346e2560f7da47986c28528ab8245f17f8557b66 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -8590,6 +8590,11 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index b58dab182842f7cfe73434cf6d503468a58efd8b..982dd7f7c742bf6fc717fd7d63b4259680041d04 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -8590,6 +8590,11 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index a85f0a545fe40bdbf9878aa548ef02cf04908ac9..a419ea59e8a0f256cb39e322fcb119167bab9a96 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -8590,6 +8590,11 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 5bad88d32e4481e35a46398698e36aba047a86f2..6fbc5075bacdc1d8f8a83788d601a4dd6c2d3c5c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index b4ceda6b18b481b7d4ba0071f48f9a726b17b626..78997f9214e4961e833148b5e136cde99223a85a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 9135c34769dd16292dff958c6d57b5b9fbfa5f5c..40177a53f54a8bb910709f652801fdaa27c22d92 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -8590,6 +8590,11 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 975f1d5e615cc255e77512887cb6f78a0625bb9f..8abc9adca0aa13f7eea40fe8ef7d6105dacd00f7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -8590,6 +8590,11 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index f1b99cc4226bbed04f69ea862913a4d86138909b..05c2859ed58cbde874c3170d2a6ef2486d967eb7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index d56a1042f1347299a012fbfce5d2c648c2fcd676..d5bf20d41745fb0ec32b6229beba83242cfcd552 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -8590,6 +8590,11 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index e98237a8b17841db9e8dafb086906b409d4a3817..093f9f94600097273e1c6acdd706925c15be100a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 847d7d32ebcf1e27cfd053ec5619e7c1e66dcc1a..1c009cd6751c2dcf0e4d97b684bf04c7bc4f0637 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Arguments with 'in' modifier cannot be used in dynamically dispatched expessions. + + ref conditional expression + ref conditional expression + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs index 77e58ea4304692dce1394d2b85dcabe2a4c197fd..956c1821d4329e47e2f4fcc76250dab6772d1b6b 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefConditionalOperatorTests.cs @@ -636,6 +636,37 @@ static void Main() ); } + [Fact] + [WorkItem(24306, "https://github.com/dotnet/roslyn/issues/24306")] + public void TestRefConditional_71() + { + var source = @" +class C +{ + static void Main() + { + + } + + void Test() + { + int local1 = 1; + int local2 = 2; + bool b = true; + + ref int r = ref b? ref local1: ref local2; + } +} +"; + var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions:TestOptions.Regular7_1); + + comp.VerifyEmitDiagnostics( + // (15,25): error CS8302: Feature 'ref conditional expression' is not available in C# 7.1. Please use language version 7.2 or greater. + // ref int r = ref b? ref local1: ref local2; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "b? ref local1: ref local2").WithArguments("ref conditional expression", "7.2").WithLocation(15, 25) + ); + } + [Fact] public void TestRefConditionalUnsafeToReturn1() {