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

VSTHRD010 now recognizes when struct members require the main thread #869

Merged
merged 2 commits into from Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -443,7 +443,7 @@ private bool AnalyzeMemberWithinContext(ITypeSymbol type, ISymbol? symbol, Synta
throw new ArgumentNullException(nameof(type));
}

bool requiresUIThread = (type.TypeKind == TypeKind.Interface || type.TypeKind == TypeKind.Class)
bool requiresUIThread = (type.TypeKind == TypeKind.Interface || type.TypeKind == TypeKind.Class || type.TypeKind == TypeKind.Struct)
&& this.MembersRequiringMainThread.Contains(type, symbol);

if (requiresUIThread)
Expand Down
@@ -1,4 +1,5 @@
[TestNS.*]
[TestNS.SomeStruct]
![TestNS.FreeThreadedType]
![TestNS2.FreeThreadedType]
[TestNS2.*]
Expand Down
Expand Up @@ -970,7 +970,7 @@ public async Task CastToManagedType_ProducesNoDiagnostic()

namespace TestNS {
class SomeClass { }
class SomeInterface { }
interface SomeInterface { }
}

class Test {
Expand Down Expand Up @@ -1053,7 +1053,7 @@ public async Task CastToManagedTypeViaAs_ProducesNoDiagnostic()

namespace TestNS {
class SomeClass { }
class SomeInterface { }
interface SomeInterface { }
}

class Test {
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public async Task CastToManagedTypeViaIs_ProducesNoDiagnostic()

namespace TestNS {
class SomeClass { }
class SomeInterface { }
interface SomeInterface { }
}

class Test {
Expand Down Expand Up @@ -1864,6 +1864,46 @@ async void SecondAsync()
await Verify.VerifyAnalyzerAsync(test, expect);
}

[Fact]
public async Task StructMembers()
{
var test = @"
namespace TestNS
{
struct SomeStruct
{
public static void DoSomething()
{
}

public string Name { get; set; }
}
}

namespace Foo
{
class MyProgram
{
static void Main()
{
TestNS.SomeStruct.DoSomething();

var st = new TestNS.SomeStruct();
st.Name = ""TheValue"";
string val = st.Name;
}
}
}
";
var expect = new DiagnosticResult[]
{
Verify.Diagnostic(DescriptorSync).WithSpan(20, 31, 20, 42).WithArguments("SomeStruct", "Test.VerifyOnUIThread"),
Verify.Diagnostic(DescriptorSync).WithSpan(23, 16, 23, 20).WithArguments("SomeStruct", "Test.VerifyOnUIThread"),
Verify.Diagnostic(DescriptorSync).WithSpan(24, 29, 24, 33).WithArguments("SomeStruct", "Test.VerifyOnUIThread"),
};
await Verify.VerifyAnalyzerAsync(test, expect);
}

private static class CodeFixIndex
{
public const int SwitchToMainThreadAsync = 0;
Expand Down