-
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
Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal #46344
Changes from all commits
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 |
---|---|---|
|
@@ -51082,12 +51082,12 @@ static void G(string x) | |
new[] { source }, options: WithNonNullTypesTrue(), | ||
parseOptions: TestOptions.Regular8); | ||
comp.VerifyDiagnostics( | ||
// (9,54): warning CS8603: Possible null reference return. | ||
// (9,9): warning CS8602: Dereference of a possibly null reference. | ||
// F(() => { if (x.Length > 0) return x; return null; }).ToString(); | ||
Diagnostic(ErrorCode.WRN_NullReferenceReturn, "null").WithLocation(9, 54), | ||
// (10,45): warning CS8603: Possible null reference return. | ||
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(() => { if (x.Length > 0) return x; return null; })").WithLocation(9, 9), | ||
// (10,9): warning CS8602: Dereference of a possibly null reference. | ||
// F(() => { if (x.Length == 0) return null; return x; }).ToString(); | ||
Diagnostic(ErrorCode.WRN_NullReferenceReturn, "null").WithLocation(10, 45)); | ||
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(() => { if (x.Length == 0) return null; return x; })").WithLocation(10, 9)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -133331,6 +133331,160 @@ internal interface IB : IA { } | |
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_01() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
class Program | ||
{ | ||
static void F<T>(Func<T> f) | ||
{ | ||
} | ||
static void M<T>(bool b, T t) where T : class | ||
{ | ||
F(() => | ||
{ | ||
if (b) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_02() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
class Program | ||
{ | ||
static void F<T>(Func<T> f) | ||
{ | ||
} | ||
static void M<T>(bool b, T t) where T : class? | ||
{ | ||
F(() => | ||
{ | ||
if (b) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_03() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
class Program | ||
{ | ||
static void F<T>(Func<T> f) | ||
{ | ||
} | ||
static void M<T>(T? t) where T : class | ||
{ | ||
F(() => | ||
{ | ||
if (t is null) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_04() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
class Program | ||
{ | ||
static void F<T>(Func<T> f) | ||
{ | ||
} | ||
static void M<T>(T? t) where T : class? | ||
{ | ||
F(() => | ||
{ | ||
if (t is null) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_05() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
using System.Threading.Tasks; | ||
class Program | ||
{ | ||
static void F<T>(Func<Task<T>> f) | ||
{ | ||
} | ||
static void M<T>(T? t) where T : class | ||
{ | ||
F(async () => | ||
{ | ||
await Task.Yield(); | ||
if (t is null) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(46342, "https://github.com/dotnet/roslyn/issues/46342")] | ||
public void LambdaNullReturn_06() | ||
{ | ||
var source = | ||
@"#nullable enable | ||
using System; | ||
using System.Threading.Tasks; | ||
class Program | ||
{ | ||
static void F<T>(Func<Task<T>> f) | ||
{ | ||
} | ||
static void M<T>(T? t) where T : class? | ||
{ | ||
F(async () => | ||
{ | ||
await Task.Yield(); | ||
if (t is null) return null; | ||
return t; | ||
}); | ||
} | ||
}"; | ||
var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); | ||
comp.VerifyEmitDiagnostics(); | ||
} | ||
|
||
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. Could we add similar tests with 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.
Added tests in #46405. |
||
[Fact] | ||
[WorkItem(45862, "https://github.com/dotnet/roslyn/issues/45862")] | ||
public void Issue_45862() | ||
|
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.
Restores behavior from before #45993.