Skip to content

Commit

Permalink
Fix tests for expresion trees (C#)
Browse files Browse the repository at this point in the history
  • Loading branch information
tats-u committed Mar 15, 2024
1 parent bbc06dd commit 51a6a8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
Expand Down Expand Up @@ -314,6 +315,7 @@ static void Main()
[Fact]
public void ExpressionsAreNotOptimized2()
{
string toObject = Environment.Version.Major > 4 ? ", Object" : "";
var source = @"
using System;
using System.Linq.Expressions;
Expand All @@ -329,7 +331,7 @@ static void Main()
}
}
";
var comp = CompileAndVerify(source, expectedOutput: @"a => Format(""a: {0} c: {1} f: {2}"", a, Convert(c, Object), ""f"")");
var comp = CompileAndVerify(source, expectedOutput: @"a => Format(""a: {0} c: {1} f: {2}"", a, Convert(c" + toObject + @"), ""f"")");

comp.VerifyDiagnostics();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Symbols;
Expand Down Expand Up @@ -13546,19 +13547,22 @@ .locals init (System.Linq.Expressions.ParameterExpression V_0)
[Fact, WorkItem(72308, "https://github.com/dotnet/roslyn/issues/72308")]
public void AsStringInExpressionTrees_06()
{
var toObject = Environment.Version.Major > 4 ? ", Object" : "";
var code = @"
using System;
using System.Linq.Expressions;

const char sp = ' ';
Expression<Func<string, string>> e = o => $""{o}l{sp}{nameof(sp)}"";";
Expression<Func<string, string>> e = o => $""{o}l{sp}{nameof(sp)}"";
Console.Write(e);";

var comp = CreateCompilation(new[] { code, GetInterpolatedStringHandlerDefinition(includeSpanOverloads: false, useDefaultParameters: false, useBoolReturns: false) });
var verifier = CompileAndVerify(comp);
var verifier = CompileAndVerify(comp, expectedOutput: @"o => Format(""{0}l{1}{2}"", o, Convert( " + toObject + @"), ""sp"")
");
verifier.VerifyDiagnostics();
verifier.VerifyIL("<top-level-statements-entry-point>", @"
{
// Code size 155 (0x9b)
// Code size 159 (0x9f)
.maxstack 7
.locals init (System.Linq.Expressions.ParameterExpression V_0)
IL_0000: ldtoken ""string""
Expand Down Expand Up @@ -13609,8 +13613,8 @@ .locals init (System.Linq.Expressions.ParameterExpression V_0)
IL_0092: ldloc.0
IL_0093: stelem.ref
IL_0094: call ""System.Linq.Expressions.Expression<System.Func<string, string>> System.Linq.Expressions.Expression.Lambda<System.Func<string, string>>(System.Linq.Expressions.Expression, params System.Linq.Expressions.ParameterExpression[])""
IL_0099: pop
IL_009a: ret
IL_0099: call ""void System.Console.Write(object)""
IL_009e: ret
}
");
}
Expand Down

0 comments on commit 51a6a8c

Please sign in to comment.