Skip to content

C#: Add model validation for constructor summary models#21416

Open
owen-mc wants to merge 2 commits intogithub:mainfrom
owen-mc:csharp/validate-constructor-summary-models
Open

C#: Add model validation for constructor summary models#21416
owen-mc wants to merge 2 commits intogithub:mainfrom
owen-mc:csharp/validate-constructor-summary-models

Conversation

@owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Mar 5, 2026

The output column of a summary model for a constructor should use Argument[this] instead of ReturnValue.

This didn't find anything, but it did for java (#21415). I also manually tested it by changing a constructor summary model to use ReturnValue and it was correctly identified when I ran csharp/ql/test/library-tests/dataflow/external-models/validatemodels.ql.

@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Mar 5, 2026
Copilot AI review requested due to automatic review settings March 5, 2026 12:12
@owen-mc owen-mc requested a review from a team as a code owner March 5, 2026 12:12
@github-actions github-actions bot added the C# label Mar 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds validation to the C# model-validation logic to detect constructor summary models that incorrectly specify their output as ReturnValue instead of Argument[this], aligning with the intended constructor modeling semantics (similar to the Java-side validation in #21415).

Changes:

  • Add a new validation check that flags constructor summary models using ReturnValue-prefixed outputs.
  • Include the new validation message in the aggregated invalidModelRow predicate output.

Comment on lines 253 to +258
/** Holds if some row in a MaD flow model appears to contain typos. */
query predicate invalidModelRow(string msg) {
msg =
[
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
KindVal::getInvalidModelKind()
getIncorrectConstructorSummaryOutput(), KindVal::getInvalidModelKind()
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The doc comment for invalidModelRow says it detects rows that "appear to contain typos", but this predicate now also reports semantic validation issues (for example, incorrect constructor summary outputs and invalid kind values). Please update the comment to reflect the broader scope (e.g., invalid/suspicious model rows) so it stays accurate.

Copilot uses AI. Check for mistakes.
@owen-mc owen-mc changed the title Add model validation for constructor summary models C#: Add model validation for constructor summary models Mar 5, 2026
string getIncorrectConstructorSummaryOutput() {
exists(string namespace, string type, string name, string output |
summaryModel(namespace, type, _, name, _, _, _, output, _, _, _) and
type = name and
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work for generics. As opposed to Java, C# doesn't used "erased" types in MaD. This means that a type could be C<T1,T2>, but the constructor name is only C. For types you need to remove everything after (and including) the first < in type before comparing to name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! I've added a commit to address this (in a different way than you suggested, which shows that I didn't even read your whole comment 😬 ). Again, I tested it by modifying an existing model to have the problem and checking that it was found by the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants