Skip to content

Commit

Permalink
Add LanguageVersion for C# 13 (#74215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Jul 2, 2024
1 parent c0c44e1 commit 70be0c7
Show file tree
Hide file tree
Showing 54 changed files with 993 additions and 793 deletions.
10 changes: 8 additions & 2 deletions docs/Language Feature Status.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ efforts behind them.

| Feature | Branch | State | Developer | Reviewer | IDE Buddy | LDM Champ |
| ------- | ------ | ----- | --------- | -------- | --------- | --------- |
| [Overload Resolution Priority](https://github.com/dotnet/csharplang/issues/7706) | PR not yet available | [In Progress](https://github.com/dotnet/roslyn/issues/74131) | [333fred](https://github.com/333fred) | [jcouv](https://github.com/jcouv), [cston](https://github.com/cston) | Not yet assigned | [333fred](https://github.com/333fred) |
| [First-class Span Types](https://github.com/dotnet/csharplang/issues/7905) | [FirstClassSpan](https://github.com/dotnet/roslyn/tree/features/FirstClassSpan) | [In Progress](https://github.com/dotnet/roslyn/issues/73445) | [jjonescz](https://github.com/jjonescz) | [cston](https://github.com/cston), [333fred](https://github.com/333fred) | | [333fred](https://github.com/333fred), [stephentoub](https://github.com/stephentoub) |
| [Semi-auto-properties](https://github.com/dotnet/csharplang/issues/140) | [semi-auto-props](https://github.com/dotnet/roslyn/tree/features/semi-auto-props) | [In Progress](https://github.com/dotnet/roslyn/issues/57012) | [Youssef1313](https://github.com/Youssef1313) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Default in deconstruction](https://github.com/dotnet/roslyn/pull/25562) | [decon-default](https://github.com/dotnet/roslyn/tree/features/decon-default) | [In Progress](https://github.com/dotnet/roslyn/issues/25559) | [jcouv](https://github.com/jcouv) | [gafter](https://github.com/gafter) | | [jcouv](https://github.com/jcouv) |
| [Roles/Extensions](https://github.com/dotnet/csharplang/issues/5497) | [roles](https://github.com/dotnet/roslyn/tree/features/roles) | [In Progress](https://github.com/dotnet/roslyn/issues/66722) | [jcouv](https://github.com/jcouv) | [AlekseyTs](https://github.com/AlekseyTs), [jjonescz](https://github.com/jjonescz) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [MadsTorgersen](https://github.com/MadsTorgersen) |
| [Ref Struct Interfaces](https://github.com/dotnet/csharplang/issues/7608) | [RefStructInterfaces](https://github.com/dotnet/roslyn/tree/features/RefStructInterfaces) | [Merged into 17.11p2](https://github.com/dotnet/roslyn/issues/72124) | [AlekseyTs](https://github.com/AlekseyTs) | [cston](https://github.com/cston), [jjonescz](https://github.com/jjonescz) | [ToddGrun](https://github.com/ToddGrun) | [agocke](https://github.com/agocke), [jaredpar](https://github.com/jaredpar) |

# C# 13.0

| Feature | Branch | State | Developer | Reviewer | IDE Buddy | LDM Champ |
| ------- | ------ | ----- | --------- | -------- | --------- | --------- |
| [Escape character](https://github.com/dotnet/csharplang/issues/7400) | N/A | [Merged into 17.9p1](https://github.com/dotnet/roslyn/pull/70497) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jcouv](https://github.com/jcouv), [RikkiGibson](https://github.com/RikkiGibson) | (no IDE impact) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) |
| [Method group natural type improvements](https://github.com/dotnet/csharplang/blob/main/proposals/method-group-natural-type-improvements.md) | main | [Merged into 17.9p2](https://github.com/dotnet/roslyn/issues/69432) | [jcouv](https://github.com/jcouv) | [AlekseyTs](https://github.com/AlekseyTs), [cston](https://github.com/cston) | (no IDE impact) | [jcouv](https://github.com/jcouv) |
| [`Lock` object](https://github.com/dotnet/csharplang/issues/7104) | [LockObject](https://github.com/dotnet/roslyn/tree/features/LockObject) | [Merged into 17.10p2](https://github.com/dotnet/roslyn/issues/71888) | [jjonescz](https://github.com/jjonescz) | [cston](https://github.com/cston), [RikkiGibson](https://github.com/RikkiGibson) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) (needs IDE fixer) | [stephentoub](https://github.com/stephentoub) |
| Implicit indexer access in object initializers | main | [Merged into 17.9p3](https://github.com/dotnet/roslyn/pull/70649) | [jcouv](https://github.com/jcouv) | [AlekseyTs](https://github.com/AlekseyTs), [cston](https://github.com/cston) | (no IDE impact) | |
| [Params-collections](https://github.com/dotnet/csharplang/issues/7700) | main | [Merged to 17.10p3](https://github.com/dotnet/roslyn/issues/71137) | [AlekseyTs](https://github.com/AlekseyTs) | [RikkiGibson](https://github.com/RikkiGibson), [333fred](https://github.com/333fred) | [akhera99](https://github.com/akhera99) (needs IDE fixer) | [MadsTorgersen](https://github.com/MadsTorgersen), [AlekseyTs](https://github.com/AlekseyTs) |
| [Ref/unsafe in iterators/async](https://github.com/dotnet/csharplang/blob/main/proposals/ref-unsafe-in-iterators-async.md) | [RefInAsync](https://github.com/dotnet/roslyn/tree/features/RefInAsync) | [Merged into 17.11p2](https://github.com/dotnet/roslyn/issues/72662) | [jjonescz](https://github.com/jjonescz) | [AlekseyTs](https://github.com/AlekseyTs), [cston](https://github.com/cston) | (no IDE impact) | |
| [Ref Struct Interfaces](https://github.com/dotnet/csharplang/issues/7608) | [RefStructInterfaces](https://github.com/dotnet/roslyn/tree/features/RefStructInterfaces) | [Merged into 17.11p2](https://github.com/dotnet/roslyn/issues/72124) | [AlekseyTs](https://github.com/AlekseyTs) | [cston](https://github.com/cston), [jjonescz](https://github.com/jjonescz) | [ToddGrun](https://github.com/ToddGrun) | [agocke](https://github.com/agocke), [jaredpar](https://github.com/jaredpar) |
| [Overload Resolution Priority](https://github.com/dotnet/csharplang/issues/7706) | PR not yet available | [In Progress](https://github.com/dotnet/roslyn/issues/74131) | [333fred](https://github.com/333fred) | [jcouv](https://github.com/jcouv), [cston](https://github.com/cston) | Not yet assigned | [333fred](https://github.com/333fred) |
| [`allows ref struct` constraint](https://github.com/dotnet/csharplang/issues/7608) | [RefStructInterfaces](https://github.com/dotnet/roslyn/tree/features/RefStructInterfaces) | [Merged into 17.11p2](https://github.com/dotnet/roslyn/issues/72124) | [AlekseyTs](https://github.com/AlekseyTs) | [cston](https://github.com/cston), [jjonescz](https://github.com/jjonescz) | [ToddGrun](https://github.com/ToddGrun) | [agocke](https://github.com/agocke), [jaredpar](https://github.com/jaredpar) |
| [Partial properties](https://github.com/dotnet/csharplang/issues/6420) | [partial-properties](https://github.com/dotnet/roslyn/tree/features/partial-properties) | [Merged into 17.11p3](https://github.com/dotnet/roslyn/issues/73090) | [RikkiGibson](https://github.com/RikkiGibson) | [jcouv](https://github.com/jcouv), [333fred](https://github.com/333fred) | [Cosifne](https://github.com/Cosifne) | [333fred](https://github.com/333fred), [RikkiGibson](https://github.com/RikkiGibson) |

# C# 12.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public CSharpUpgradeProjectCodeFixProvider()
"CS9058",
"CS9194",
"CS9202",
"CS9260",
];

public override string UpgradeThisProjectResource => CSharpCodeFixesResources.Upgrade_this_project_to_csharp_language_version_0;
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10448,7 +10448,7 @@ static bool isCandidateUnique(ref MethodSymbol? method, MethodSymbol candidate)
/// </summary>
private MethodSymbol? GetUniqueSignatureFromMethodGroup(BoundMethodGroup node)
{
if (Compilation.LanguageVersion < LanguageVersionFacts.CSharpNext)
if (Compilation.LanguageVersion < LanguageVersion.CSharp13)
{
return GetUniqueSignatureFromMethodGroup_CSharp10(node);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6632,6 +6632,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_FeatureNotAvailableInVersion12" xml:space="preserve">
<value>Feature '{0}' is not available in C# 12.0. Please use language version {1} or greater.</value>
</data>
<data name="ERR_FeatureNotAvailableInVersion13" xml:space="preserve">
<value>Feature '{0}' is not available in C# 13.0. Please use language version {1} or greater.</value>
</data>
<data name="ERR_UnexpectedArgumentList" xml:space="preserve">
<value>Unexpected argument list.</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,7 @@ internal enum ErrorCode
INF_IdentifierConflictWithContextualKeyword = 9258,

ERR_InlineArrayAttributeOnRecord = 9259,
ERR_FeatureNotAvailableInVersion13 = 9260,

// Note: you will need to do the following after adding errors:
// 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs)
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,7 @@ or ErrorCode.WRN_PartialPropertySignatureDifference
or ErrorCode.ERR_PartialPropertyRequiredDifference
or ErrorCode.INF_IdentifierConflictWithContextualKeyword
or ErrorCode.ERR_InlineArrayAttributeOnRecord
or ErrorCode.ERR_FeatureNotAvailableInVersion13
=> false,
};
#pragma warning restore CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value.
Expand Down
11 changes: 7 additions & 4 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,16 +471,19 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
// PREFER reporting diagnostics in binding when diagnostics do not affect the shape of the syntax tree

// C# preview features.
case MessageID.IDS_FeatureStringEscapeCharacter:
case MessageID.IDS_FeatureRefStructInterfaces:
case MessageID.IDS_FeatureFieldAndValueKeywords:
return LanguageVersion.Preview;

// C# 13.0 features.
case MessageID.IDS_FeatureStringEscapeCharacter: // lexer check
case MessageID.IDS_FeatureImplicitIndexerInitializer:
case MessageID.IDS_FeatureLockObject:
case MessageID.IDS_FeatureParamsCollections:
case MessageID.IDS_FeatureRefUnsafeInIteratorAsync:
case MessageID.IDS_FeatureRefStructInterfaces:
case MessageID.IDS_FeatureAllowsRefStructConstraint:
case MessageID.IDS_FeaturePartialProperties:
case MessageID.IDS_FeatureFieldAndValueKeywords:
return LanguageVersion.Preview;
return LanguageVersion.CSharp13;

// C# 12.0 features.
case MessageID.IDS_FeatureLambdaOptionalParameters: // semantic check
Expand Down
31 changes: 29 additions & 2 deletions src/Compilers/CSharp/Portable/LanguageVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,23 @@ public enum LanguageVersion
/// </summary>
CSharp12 = 1200,

/// <summary>
/// C# language version 13.0
/// <br/>
/// Features:
/// <list type="bullet">
/// <item><description>Escape character</description></item>
/// <item><description>Method group natural type improvements</description></item>
/// <item><description>`Lock` object</description></item>
/// <item><description>Implicit indexer access in object initializers</description></item>
/// <item><description>`params` collections</description></item>
/// <item><description>ref/unsafe in iterators/async</description></item>
/// <item><description>`allows ref struct` constraint</description></item>
/// <item><description>Partial properties</description></item>
/// </list>
/// </summary>
CSharp13 = 1300,

/// <summary>
/// The latest major supported version.
/// </summary>
Expand Down Expand Up @@ -273,6 +290,7 @@ internal static bool IsValid(this LanguageVersion value)
case LanguageVersion.CSharp10:
case LanguageVersion.CSharp11:
case LanguageVersion.CSharp12:
case LanguageVersion.CSharp13:
case LanguageVersion.Preview:
return true;
}
Expand Down Expand Up @@ -314,6 +332,8 @@ internal static ErrorCode GetErrorCode(this LanguageVersion version)
return ErrorCode.ERR_FeatureNotAvailableInVersion11;
case LanguageVersion.CSharp12:
return ErrorCode.ERR_FeatureNotAvailableInVersion12;
case LanguageVersion.CSharp13:
return ErrorCode.ERR_FeatureNotAvailableInVersion13;
default:
throw ExceptionUtilities.UnexpectedValue(version);
}
Expand Down Expand Up @@ -385,6 +405,8 @@ public static string ToDisplayString(this LanguageVersion version)
return "11.0";
case LanguageVersion.CSharp12:
return "12.0";
case LanguageVersion.CSharp13:
return "13.0";
case LanguageVersion.Default:
return "default";
case LanguageVersion.Latest:
Expand Down Expand Up @@ -501,6 +523,11 @@ public static bool TryParse(string? version, out LanguageVersion result)
result = LanguageVersion.CSharp12;
return true;

case "13":
case "13.0":
result = LanguageVersion.CSharp13;
return true;

default:
result = LanguageVersion.Default;
return false;
Expand All @@ -517,13 +544,13 @@ public static LanguageVersion MapSpecifiedToEffectiveVersion(this LanguageVersio
case LanguageVersion.Latest:
case LanguageVersion.Default:
case LanguageVersion.LatestMajor:
return LanguageVersion.CSharp12;
return LanguageVersion.CSharp13;
default:
return version;
}
}

internal static LanguageVersion CurrentVersion => LanguageVersion.CSharp12;
internal static LanguageVersion CurrentVersion => LanguageVersion.CSharp13;

/// <summary>Inference of tuple element names was added in C# 7.1</summary>
internal static bool DisallowInferredTupleElementNames(this LanguageVersion self)
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp13 = 1300 -> Microsoft.CodeAnalysis.CSharp.LanguageVersion
[RSEXPERIMENTAL002]Microsoft.CodeAnalysis.CSharp.InterceptableLocation
[RSEXPERIMENTAL002]abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.Data.get -> string!
[RSEXPERIMENTAL002]abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.GetDisplayLocation() -> string!
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 70be0c7

Please sign in to comment.