Repository navigation
ConstantAttributeAnalyzer: inspect and report tuple conversions - #999
Merged
Merged
Conversation
omsmith
force-pushed
the
omsmith/constant-tuple-conversions
branch
from
October 16, 2026 18:31
c1899b0 to
89f4258
Compare
omsmith
commented
Oct 16, 2026
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 /**/); } |
Contributor
Author
There was a problem hiding this comment.
These already worked, just adding the tests for it
omsmith
commented
Oct 16, 2026
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) /**/; } |
Contributor
Author
There was a problem hiding this comment.
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)
Contributor
Author
There was a problem hiding this comment.
Either of these cases previously fell into conversion.OperatorMethod is null and so we bailed despite the implicit tuple conversion existing.
omsmith
commented
Oct 16, 2026
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; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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
j3parker
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SPLA-4875