提交 91fa14da 编写于 作者: V vsadov

Constrains availability of ref conditional expressions to language versions 7.2 and higher

Fixes:#24306
上级 ea75a538
...@@ -3521,6 +3521,10 @@ private BoundExpression BindConditionalOperator(ConditionalExpressionSyntax node ...@@ -3521,6 +3521,10 @@ private BoundExpression BindConditionalOperator(ConditionalExpressionSyntax node
diagnostics.Add(ErrorCode.ERR_RefConditionalNeedsTwoRefs, whenTrue.GetFirstToken().GetLocation()); diagnostics.Add(ErrorCode.ERR_RefConditionalNeedsTwoRefs, whenTrue.GetFirstToken().GetLocation());
} }
} }
else
{
CheckFeatureAvailability(node, MessageID.IDS_FeatureRefConditional, diagnostics);
}
BoundExpression condition = BindBooleanExpression(node.Condition, diagnostics); BoundExpression condition = BindBooleanExpression(node.Condition, diagnostics);
......
...@@ -10700,6 +10700,15 @@ internal class CSharpResources { ...@@ -10700,6 +10700,15 @@ internal class CSharpResources {
} }
} }
/// <summary>
/// Looks up a localized string similar to ref conditional expression.
/// </summary>
internal static string IDS_FeatureRefConditional {
get {
return ResourceManager.GetString("IDS_FeatureRefConditional", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to ref extension methods. /// Looks up a localized string similar to ref extension methods.
/// </summary> /// </summary>
......
...@@ -4264,6 +4264,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -4264,6 +4264,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureRefStructs" xml:space="preserve"> <data name="IDS_FeatureRefStructs" xml:space="preserve">
<value>ref structs</value> <value>ref structs</value>
</data> </data>
<data name="IDS_FeatureRefConditional" xml:space="preserve">
<value>ref conditional expression</value>
</data>
<data name="CompilationC" xml:space="preserve"> <data name="CompilationC" xml:space="preserve">
<value>Compilation (C#): </value> <value>Compilation (C#): </value>
</data> </data>
......
...@@ -145,6 +145,7 @@ internal enum MessageID ...@@ -145,6 +145,7 @@ internal enum MessageID
IDS_FeatureRefExtensionMethods = MessageBase + 12728, IDS_FeatureRefExtensionMethods = MessageBase + 12728,
IDS_StackAllocExpression = MessageBase + 12729, IDS_StackAllocExpression = MessageBase + 12729,
IDS_FeaturePrivateProtected = MessageBase + 12730, IDS_FeaturePrivateProtected = MessageBase + 12730,
IDS_FeatureRefConditional = MessageBase + 12731,
} }
// Message IDs may refer to strings that need to be localized. // Message IDs may refer to strings that need to be localized.
...@@ -192,6 +193,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) ...@@ -192,6 +193,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_FeatureRefStructs: case MessageID.IDS_FeatureRefStructs:
case MessageID.IDS_FeatureReadOnlyStructs: case MessageID.IDS_FeatureReadOnlyStructs:
case MessageID.IDS_FeatureRefExtensionMethods: case MessageID.IDS_FeatureRefExtensionMethods:
case MessageID.IDS_FeatureRefConditional:
return LanguageVersion.CSharp7_2; return LanguageVersion.CSharp7_2;
// C# 7.1 features. // C# 7.1 features.
......
...@@ -8590,6 +8590,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference ...@@ -8590,6 +8590,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett ...@@ -8590,6 +8590,11 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe ...@@ -8590,6 +8590,11 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé ...@@ -8590,6 +8590,11 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr ...@@ -8590,6 +8590,11 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w ...@@ -8590,6 +8590,11 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl ...@@ -8590,6 +8590,11 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T ...@@ -8590,6 +8590,11 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ ...@@ -8590,6 +8590,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target> <target state="new">Arguments with 'in' modifier cannot be used in dynamically dispatched expessions.</target>
<note /> <note />
</trans-unit> </trans-unit>
<trans-unit id="IDS_FeatureRefConditional">
<source>ref conditional expression</source>
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>
\ No newline at end of file
...@@ -636,6 +636,37 @@ static void Main() ...@@ -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] [Fact]
public void TestRefConditionalUnsafeToReturn1() public void TestRefConditionalUnsafeToReturn1()
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册