Skip to content

Commit

Permalink
[generator] Avoid interpolated strings
Browse files Browse the repository at this point in the history
Context: dotnet/roslyn#55564
Context: https://discord.com/channels/732297728826277939/732297837953679412/874959446747533323

.NET 6 Preview 7 introduced a compiler regression: use of
[C#6 string interpolation][0] when `$(LangVersion)` < 10.0
results in a CS8400 error:

	error CS8400: Feature 'interpolated string handlers' is not available in C# 8.0. Please use language version 10.0 or greater.

Because `azure-pipelines.yaml` specifies `DotNetCoreVersion: 6.0.x`,
our CI machines get auto-bumped to .NET 6 Preview 7, causing *all*
PR builds to now fail with this CS8400 failure.

There are two possible solutions:

 1. *Avoid* .NET 6 Preview 7.
 2. Remove select use of string interpolation.

(1) was initially done on #865, by using:

	DotNetCoreVersion: 6.0.100-preview.6.21355.2

However, it's not *all* use of string interpolation which triggers
the CS8400 error.  It's just use of string interpolation within
`RegisterAttr.cs`, in 3 locations.

Update `RegisterAttr.cs` to use `StringBuilder.Append()` calls
instead of string interpolation.  The resulting code is slightly
more annoying to read, but should perform better (slightly), and
avoids the CS8400 error.

[0]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
  • Loading branch information
jonpryor committed Aug 19, 2021
1 parent ff27142 commit 952a6cd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/generator/SourceWriters/Attributes/RegisterAttr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public override void WriteAttribute (CodeWriter writer)
var sb = new StringBuilder ();

if (UseGlobal)
sb.Append ($"[global::Android.Runtime.Register (\"{Name}\"");
sb.Append ("[global::Android.Runtime.Register (\"").Append (Name).Append ("\"");
else
sb.Append ($"[Register (\"{Name}\"");
sb.Append ("[Register (\"").Append (Name).Append ("\"");

if ((Signature.HasValue () || Connector.HasValue ()) && !UseShortForm)
sb.Append ($", \"{Signature}\", \"{Connector}\"");
sb.Append (", \"").Append (Signature).Append ("\", \"").Append (Connector).Append ("\"");

if (DoNotGenerateAcw && !AcwLast)
sb.Append (", DoNotGenerateAcw=true");
Expand Down

0 comments on commit 952a6cd

Please sign in to comment.