@@ -5269,6 +5269,11 @@ impl<'a, 'ast> Generator<'a, 'ast> {
52695269 }
52705270 LiteralExpression :: InterpolatedString ( interpolated) => {
52715271 let mut current: Option < DataId > = None ;
5272+ // `$"{s}"` with `s` a null string: the hole's text is `s`
5273+ // itself, and with nothing to concatenate it to, nothing turns
5274+ // that null into the "" C# gives. Noted here, fixed after the
5275+ // loop, once it is known to be the only piece.
5276+ let mut sole_string_hole = false ;
52725277 for part in interpolated. parts {
52735278 let piece_slot = match part {
52745279 InterpolationPart :: Text ( text) => {
@@ -5308,12 +5313,17 @@ impl<'a, 'ast> Generator<'a, 'ast> {
53085313 hole. span . clone ( ) ,
53095314 ) ;
53105315 // `{x,-8}` — padded to the field width
5311- self . align_to_width ( ctx, text, hole)
5316+ let padded = self . align_to_width ( ctx, text, hole) ;
5317+ sole_string_hole = current. is_none ( )
5318+ && padded == slot
5319+ && self . extern_type_name ( & ty) . as_deref ( ) == Some ( "SystemString" ) ;
5320+ padded
53125321 }
53135322 } ;
53145323 current = Some ( match current {
53155324 None => piece_slot,
53165325 Some ( previous) => {
5326+ sole_string_hole = false ;
53175327 let out = self . temp ( "SystemString" ) ;
53185328 self . call_extern (
53195329 ctx,
@@ -5325,9 +5335,23 @@ impl<'a, 'ast> Generator<'a, 'ast> {
53255335 }
53265336 } ) ;
53275337 }
5328- let slot = current. unwrap_or_else ( || {
5329- self . constant ( "SystemString" , "" , HeapInit :: Str ( String :: new ( ) ) )
5330- } ) ;
5338+ let slot = match current {
5339+ Some ( value) if sole_string_hole => {
5340+ // Concat treats a null as "", which is the result C#
5341+ // gives for an interpolated null
5342+ let empty = self . string_constant ( "" ) ;
5343+ let out = self . temp ( "SystemString" ) ;
5344+ self . call_extern (
5345+ ctx,
5346+ "SystemString.__Concat__SystemString_SystemString__SystemString" ,
5347+ & [ value, empty, out] ,
5348+ interpolated. span . clone ( ) ,
5349+ ) ;
5350+ out
5351+ }
5352+ Some ( value) => value,
5353+ None => self . constant ( "SystemString" , "" , HeapInit :: Str ( String :: new ( ) ) ) ,
5354+ } ;
53315355 Piece :: Value ( slot, self . corlib_type ( "String" ) )
53325356 }
53335357 other => {
0 commit comments