-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Track additional state for "maybe null even if not nullable" #39778
Changes from 1 commit
b027ec9
660ab31
970fd18
9afe4ac
0039064
5ddeaa5
55ed425
4741829
88ef98e
bb8e3a2
2afc198
bb293f9
e6474bf
bf34fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.CSharp.Test.Utilities; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
@@ -3788,5 +3787,39 @@ void M() {} | |
var symbolInfo = specModel.GetSymbolInfo(newAttributeUsage.ArgumentList.Arguments[0].Expression); | ||
Assert.Equal(SpecialType.System_String, ((IFieldSymbol)symbolInfo.Symbol).Type.SpecialType); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(38638, "https://github.com/dotnet/roslyn/issues/38638")] | ||
public void TypeParameter_Default() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
abstract class A<T> | ||
{ | ||
internal abstract void F<U>() where U : T; | ||
} | ||
class B1<T> : A<T> | ||
{ | ||
internal override void F<U>() { _ = default(U); } | ||
} | ||
class B2 : A<int?> | ||
{ | ||
internal override void F<U>() { _ = default(U); } | ||
}"; | ||
var comp = CreateCompilation(source); | ||
comp.VerifyDiagnostics(); | ||
var tree = comp.SyntaxTrees[0]; | ||
var model = comp.GetSemanticModel(tree); | ||
var exprs = tree.GetRoot().DescendantNodes().OfType<DefaultExpressionSyntax>().ToArray(); | ||
verify(exprs[0], PublicNullableAnnotation.NotAnnotated, PublicNullableFlowState.MaybeNull); | ||
verify(exprs[1], PublicNullableAnnotation.Annotated, PublicNullableFlowState.MaybeNull); | ||
|
||
void verify(DefaultExpressionSyntax expr, PublicNullableAnnotation expectedAnnotation, PublicNullableFlowState expectedState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider putting expected values first or labeling in order to match the conventions of the xunit Assert methods. #ByDesign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll leave as is since this matches similar local functions in this class. In reply to: 348226625 [](ancestors = 348226625) |
||
{ | ||
var info = model.GetTypeInfo(expr).Nullability; | ||
Assert.Equal(expectedAnnotation, info.Annotation); | ||
Assert.Equal(expectedState, info.FlowState); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this-- is it expected that we could throw out of the 'try' block at any point and then run the 'finally' block, so we have to be as pessimistic as possible here? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we assume an exception could have been thrown between the assignments above, although perhaps we could do better for those simple assignments.
In reply to: 348225225 [](ancestors = 348225225)