Skip to content

Commit

Permalink
Use LangVersion=8 where feasible in testing
Browse files Browse the repository at this point in the history
This should allow us to avoid accidentally using C# 9+ features, at least in most cases.

The standalone-console and standalone-console-without-using templates are unchanged, as many examples using them expect to use top-level statements.
(Once we've got as far as C# 10, we should be able to use LangVersion for all projects.)
  • Loading branch information
jskeet committed Nov 21, 2024
1 parent 8d8aa8b commit 90dac41
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 11 deletions.
7 changes: 5 additions & 2 deletions standard/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ A generic class declaration shall not use `System.Attribute` as a direct or indi

> *Example*:
>
> <!-- Example: {template:"standalone-lib", name:"AttributeCantBeGeneric", expectedErrors:["CS8936"], ignoredWarnings:["CS0169"]} -->
> <!-- Example: {template:"standalone-lib", name:"AttributeCantBeGeneric", expectedErrors:["CS8400"], ignoredWarnings:["CS0169"]} -->
> ```csharp
> public class B : Attribute {}
> public class C<T> : B {} // Error – generic cannot be an attribute
Expand Down Expand Up @@ -617,6 +617,7 @@ It is important to understand that the inclusion or exclusion of a call to a con
> <!-- Example: {template:"standalone-lib", name:"ConditionalMethods3"} -->
> ```csharp
> // File Class1.cs:
> using System;
> using System.Diagnostics;
> class Class1
> {
Expand Down Expand Up @@ -659,6 +660,7 @@ The use of conditional methods in an inheritance chain can be confusing. Calls m
> <!-- Example: {template:"standalone-console", name:"ConditionalMethods4", expectedOutput:["Class2.M executed"]} -->
> ```csharp
> // File Class1.cs
> using System;
> using System.Diagnostics;
> class Class1
> {
Expand Down Expand Up @@ -718,6 +720,7 @@ It is important to note that the inclusion or exclusion of an attribute specific
> <!-- Example: {template:"standalone-lib", name:"ConditionalAttributeClasses2"} -->
> ```csharp
> // File Test.cs:
> using System;
> using System.Diagnostics;
> [Conditional("DEBUG")]
> public class TestAttribute : Attribute {}
Expand Down Expand Up @@ -1011,7 +1014,7 @@ Specifies that a non-nullable return value may be null.
> *Example*: Consider the following generic method:
>
> <!-- Example: {template:"code-in-class-lib-without-using", name:"MaybeNull1Attribute", replaceEllipsis:true, customEllipsisReplacements: ["return default;"]} -->
> <!-- Example: {template:"code-in-class-lib", name:"MaybeNull1Attribute", replaceEllipsis:true, customEllipsisReplacements: ["return default;"]} -->
> ```csharp
> #nullable enable
> public T? Find<T>(IEnumerable<T> sequence, Func<T, bool> predicate) { ... }
Expand Down
2 changes: 1 addition & 1 deletion standard/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Some conversions in the language are defined from expressions to types, others f
> *Example*:
>
> <!-- Example: {template:"code-in-class-lib-without-using", name:"Conversions2", ignoredWarnings:["CS0414"]} -->
> <!-- Example: {template:"code-in-class-lib", name:"Conversions2", ignoredWarnings:["CS0414"]} -->
> ```csharp
> enum Color { Red, Blue, Green }
>
Expand Down
2 changes: 1 addition & 1 deletion standard/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ There are several restrictions on where a `yield` statement can appear, as descr
> *Example*: The following example shows some valid and invalid uses of `yield` statements.
>
> <!-- Example: {template:"code-in-class-lib-without-using", name:"YieldStatement", expectedErrors:["CS1625","CS1625","CS1626","CS1631","CS1643","CS1621","CS1624"], expectedWarnings:["CS0162"]} -->
> <!-- Example: {template:"code-in-class-lib", name:"YieldStatement", expectedErrors:["CS1625","CS1625","CS1626","CS1631","CS1643","CS1621","CS1624"], expectedWarnings:["CS0162"]} -->
> ```csharp
> delegate IEnumerable<int> D();
>
Expand Down
2 changes: 2 additions & 0 deletions tools/example-templates/additional-files/Attr1Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class Attr1Attribute : Attribute
{
Expand Down
3 changes: 2 additions & 1 deletion tools/example-templates/additional-files/Attr2Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class Attr2Attribute : Attribute
{
Expand All @@ -11,4 +13,3 @@ public Attr2Attribute(string name)
// get { return name; }
// }
}

2 changes: 2 additions & 0 deletions tools/example-templates/additional-files/Attr3Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class Attr3Attribute : Attribute
{
Expand Down
2 changes: 2 additions & 0 deletions tools/example-templates/additional-files/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

public static class Extensions
{
public static int ToInt32(this string s) => Int32.Parse(s);
Expand Down
2 changes: 2 additions & 0 deletions tools/example-templates/additional-files/SimpleAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class SimpleAttribute : Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion tools/example-templates/code-in-class-lib/Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion tools/example-templates/code-in-main/Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>annotations</Nullable>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions tools/example-templates/extern-lib/ExampleProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<EnableDefaultItems>false</EnableDefaultItems>
<NoWarn>CS0169</NoWarn>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tools/example-templates/extern-lib/ExternN2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tools/example-templates/extern-lib/ExternR1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tools/example-templates/extern-lib/ExternX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tools/example-templates/extern-lib/ExternY.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultItems>false</EnableDefaultItems>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/example-templates/standalone-lib/Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>$example-name</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>annotations</Nullable>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>

0 comments on commit 90dac41

Please sign in to comment.