Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix oblivious analysis of type parameters #4246

Merged
merged 4 commits into from
Oct 5, 2020

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Sep 30, 2020

Fixes #4040

@jcouv jcouv self-assigned this Sep 30, 2020
Comment on lines 560 to 568
foreach (var typeParameter in typeParameters)
{
if (ObliviousDetector.CheckTypeParameterConstraints(typeParameter))
{
return true;
}
}

return false;
Copy link
Member

@Evangelink Evangelink Oct 2, 2020

Choose a reason for hiding this comment

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

What about

Suggested change
foreach (var typeParameter in typeParameters)
{
if (ObliviousDetector.CheckTypeParameterConstraints(typeParameter))
{
return true;
}
}
return false;
return typeParameters.Any(typeParameter => ObliviousDetector.CheckTypeParameterConstraints(typeParameter));
``` #WontFix

}

var typeParameters = ((IMethodSymbol)symbol).TypeParameters;
foreach (var typeParameter in typeParameters)
Copy link
Member

@Evangelink Evangelink Oct 2, 2020

Choose a reason for hiding this comment

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

Same suggestion here. #WontFix

Comment on lines +885 to +893
if (symbol.IsReferenceType &&
symbol.NullableAnnotation() == NullableAnnotation.None)
{
// Example:
// I<TReferenceType~>
return true;
}

return false;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (symbol.IsReferenceType &&
symbol.NullableAnnotation() == NullableAnnotation.None)
{
// Example:
// I<TReferenceType~>
return true;
}
return false;
// Example:
// I<TReferenceType~>
return symbol.IsReferenceType &&
symbol.NullableAnnotation() == NullableAnnotation.None;

{
// where T : class~
return true;
}

foreach (var constraintType in symbol.ConstraintTypes)
Copy link
Member

@Evangelink Evangelink Oct 2, 2020

Choose a reason for hiding this comment

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

Could also be refactored as a .Any() call. #WontFix

Copy link
Member Author

@jcouv jcouv Oct 2, 2020

Choose a reason for hiding this comment

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

I prefer the explicit loop style. One reason is it's easier to step through. #WontFix

C<T>
";

await VerifyCSharpAsync(source, shippedText, unshippedText, System.Array.Empty<DiagnosticResult>());
Copy link
Member

Choose a reason for hiding this comment

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

I am curious on the why you are passing the empty array. Is it for clarity? Allocation? Something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will remove. Thanks

@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #4246 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           master    #4246    +/-   ##
========================================
  Coverage   95.80%   95.81%            
========================================
  Files        1170     1168     -2     
  Lines      264491   264737   +246     
  Branches    15961    15969     +8     
========================================
+ Hits       253390   253645   +255     
+ Misses       9082     9076     -6     
+ Partials     2019     2016     -3     

@jcouv jcouv marked this pull request as ready for review October 2, 2020 21:57
@jcouv jcouv requested a review from a team as a code owner October 2, 2020 21:57
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.

Use of oblivious types when using generic type constraint 'class'
3 participants