Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Braces need escaping in raw string interpolation on net472 #61355

Closed
jcouv opened this issue May 17, 2022 · 3 comments · Fixed by #61387
Closed

Braces need escaping in raw string interpolation on net472 #61355

jcouv opened this issue May 17, 2022 · 3 comments · Fixed by #61387
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@jcouv
Copy link
Member

jcouv commented May 17, 2022

The following test fails on net472 with System.FormatException : Input string was not in a correct format..
The problem is with the format string passed to string.Format, where the open brace (first character) isn't escaped: IL_000a: ldstr "{\r\n // Code size ....

        [Fact]
        public void TODO2()
        {
            int count = 31;
            string op = "shl";
            var value = $$"""
{
  // Code size        5 (0x5)
  .maxstack  2
  IL_0000:  ldarg.0
  IL_0001:  ldc.i4.s   {{count}}
  IL_0003:  {{op}}
  IL_0004:  ret
}
""";
        }
Message: 
System.FormatException : Input string was not in a correct format.

  Stack Trace: 
StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
String.Format(String format, Object arg0, Object arg1)
NativeIntegerTests.TODO2() line 14939
.method public hidebysig 
	instance void TODO2 () cil managed 
{
	.custom instance void [xunit.core]Xunit.FactAttribute::.ctor() = (
		01 00 00 00
	)
	// Method begins at RVA 0x24f4fc
	// Code size 29 (0x1d)
	.maxstack 3
	.locals init (
		[0] int32 count,
		[1] string op,
		[2] string 'value'
	)

	// {
	IL_0000: nop
	// int num = 31;
	IL_0001: ldc.i4.s 31
	IL_0003: stloc.0
	// string arg = "shl";
	IL_0004: ldstr "shl"
	IL_0009: stloc.1
	// string text = string.Format("{\r\n  // Code size        5 (0x5)\r\n  .maxstack  2\r\n  IL_0000:  ldarg.0\r\n  IL_0001:  ldc.i4.s   {0}\r\n  IL_0003:  {1}\r\n  IL_0004:  ret\r\n}", num, arg);
	IL_000a: ldstr "{\r\n  // Code size        5 (0x5)\r\n  .maxstack  2\r\n  IL_0000:  ldarg.0\r\n  IL_0001:  ldc.i4.s   {0}\r\n  IL_0003:  {1}\r\n  IL_0004:  ret\r\n}"
	IL_000f: ldloc.0
	IL_0010: box [mscorlib]System.Int32
	IL_0015: ldloc.1
	IL_0016: call string [mscorlib]System.String::Format(string, object, object)
	IL_001b: stloc.2
	// }
	IL_001c: ret
} // end of method NativeIntegerTests::TODO2

Relates to test plan #55306

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label May 17, 2022
@CyrusNajmabadi
Copy link
Member

Looking now.

@CyrusNajmabadi
Copy link
Member

CyrusNajmabadi commented May 18, 2022

This may be a dupe of #59607. @jcouv do you repro this on latest builds?

@jcouv
Copy link
Member Author

jcouv commented May 19, 2022

From offline investigation with @CyrusNajmabadi, we found the problem was using an old toolset compiler (Compiler version: '4.2.0-1.22108.11 (a29b6ae8)'). We couldn't repro with new bits (in unittest).
Closing

@jcouv jcouv closed this as completed May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants