Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ private void MakeInterpolatedStringFormat(BoundInterpolatedString node, out Boun
formatString.Builder.Append(":").Append(fillin.Format.ConstantValue.StringValue);
}
formatString.Builder.Append("}");
expressions.Add(fillin.Value); // NOTE: must still be lowered
var value = fillin.Value;
if (value.Type?.TypeKind == TypeKind.Dynamic)
{
value = MakeConversion(value, _compilation.ObjectType, @checked: false);
}

expressions.Add(value); // NOTE: must still be lowered
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ static void Main(string[] args)
CompileAndVerify(source, expectedOutput: expectedOutput);
}

[Fact, WorkItem(306), WorkItem(308)]
public void DynamicInterpolation()
{
string source =
@"using System;
using System.Linq.Expressions;
class Program
{
static void Main(string[] args)
{
dynamic nil = null;
dynamic a = new string[] {""Hello"", ""world""};
Console.WriteLine($""<{nil}>"");
Console.WriteLine($""<{a}>"");
}
Expression<Func<string>> M(dynamic d) {
return () => $""Dynamic: {d}"";
}
}";
string expectedOutput = @"<>
<System.String[]>";
var verifier = CompileAndVerify(source, new[] { SystemCoreRef, CSharpRef }, expectedOutput: expectedOutput).VerifyDiagnostics();
}

[Fact]
public void UnclosedInterpolation01()
{
Expand Down