Skip to content

ConstantAttributeAnalyzer: inspect and report tuple conversions - #999

Merged
omsmith merged 2 commits into
mainfrom
omsmith/constant-tuple-conversions
Oct 16, 2026
Merged

omsmith merged 2 commits into
mainfrom
omsmith/constant-tuple-conversions

Conversation

@omsmith

@omsmith omsmith commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

SPLA-4875

@omsmith
omsmith requested a review from JeffAshton October 16, 2026 18:31
@omsmith
omsmith requested a review from j3parker as a code owner October 16, 2026 18:31
@omsmith
omsmith force-pushed the omsmith/constant-tuple-conversions branch from c1899b0 to 89f4258 Compare October 16, 2026 18:31
Comment on lines +278 to +281
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = (Constants.String, Constants.String); }
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = (Constants.String, trusted); }
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = (Constants.String, /* NonConstantPassedToConstantParameter(value) */ variable /**/); }
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = (Constants.String, /* NonConstantPassedToConstantParameter(value) */ untrusted /**/); }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These already worked, just adding the tests for it

Comment on lines +282 to +283
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = /* NonConstantPassedToConstantParameter(value) */ true ? (Constants.String, Constants.String) : (Constants.String, Constants.String) /**/; }
{ (Types.ConstantStruct X, Types.ConstantStruct Y) v = /* NonConstantPassedToConstantParameter(value) */ true ? (Constants.String, variable) : (Constants.String, Constants.String) /**/; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally the former of these two would work, but would require special-casing the ternarys etc. etc. (we similarly don't special case switch expressions or anything)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Either of these cases previously fell into conversion.OperatorMethod is null and so we bailed despite the implicit tuple conversion existing.

Comment on lines +165 to 175
// Operand is a constant value or string.Empty, so trust it
IOperation operand = conversion.Operand;
if( operand.ConstantValue.HasValue || IsStringEmpty( operand ) ) {
return;
}

IMethodSymbol @operator = conversion.OperatorMethod;
if( @operator is null ) {
// Operand was defined as [Constant] already, so trust it
ISymbol operandSymbol = conversion.SemanticModel.GetSymbolInfo( operand.Syntax ).Symbol;
if( operandSymbol is not null && HasAttribute( operandSymbol, constantAttribute ) ) {
return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basically moved to check constant operands first, and anything after that is deciding if the conversion was to something with a [Constant] parameter that we should raise a diagnostic for

@omsmith
omsmith merged commit b5b0061 into main Oct 16, 2026
5 checks passed
@omsmith
omsmith deleted the omsmith/constant-tuple-conversions branch October 16, 2026 18:39
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