Skip to content

fix ConstantAttributeAnalyzer null reference#974

Merged
omsmith merged 1 commit into
mainfrom
omsmith/constant-fix
May 15, 2026
Merged

fix ConstantAttributeAnalyzer null reference#974
omsmith merged 1 commit into
mainfrom
omsmith/constant-fix

Conversation

@omsmith
Copy link
Copy Markdown
Contributor

@omsmith omsmith commented May 15, 2026

Fixes a NullReferenceException during analysis of an InterpolatedStringHandler usage.

Possible to add a test, but requires a couple of package updates that I don't want to verify are safe, at the moment.

[InterpolatedStringHandler]
public sealed class MyString {
  public MyString( int a, int b ) {}
  public void AppendLiteral( [Constant] string s ) {}
  public void AppendFormatted( [Constant] string s ) {}
}

public sealed class C {
  public void M( bool x ) {

    R(
      $"""
      FOO
      {( x ? "x" : "y" )}
      """
    );
  }

  public void R( MyString s ) {}
}

This desugars to

  public void M( bool x ) {
    MyString <> = new MyString( 4, 1 );
    <>.AppendLiteral( "FOO\n" );
    <>.AppendFormatted( x ? "x" : "y" );
    R( <> );
  }

However, the syntax for the operation of <>.AppendFormatted( x ? "x" : "y" ); is still from the original interpolated string; both argument.Syntax and argument.Value.Syntax are ConditionalExpressionSyntax rather than an ArgumentSyntax.

SPLA-3693

@omsmith omsmith requested a review from j3parker as a code owner May 15, 2026 15:13
Copy link
Copy Markdown
Member

@j3parker j3parker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol nice

@omsmith omsmith merged commit 26c3283 into main May 15, 2026
2 checks passed
@omsmith omsmith deleted the omsmith/constant-fix branch May 15, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants