Skip to content

Commit

Permalink
Merge pull request #774 from manfred-brands/Issue766_PartialTestClasses
Browse files Browse the repository at this point in the history
Prevent exception when fields are declared in a different source file.
  • Loading branch information
mikkelbu authored Jul 27, 2024
2 parents 5fde5a5 + cb9eb5d commit 48bf08f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,8 @@ public partial class TestFixture
{{
private const double Tolerance = 1E-10;
private IDisposable? field;
private static IDisposable? Property {{ get; set; }}
[SetUp]
Expand All @@ -1059,6 +1061,8 @@ public partial class TestFixture
[Test]
public void SomeTest()
{
// field needs Disposal, but as TearDown is in a different source 'file' we cannot check if it is.
field = new DummyDisposable();
SomeAsserts();
}
}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ private static bool NeedsDisposal(SemanticModel model, ExpressionSyntax expressi
{
if (IsPossibleDisposableCreation(expression))
{
if (model.SyntaxTree != expression.SyntaxTree)
{
// It might need it, but we cannot check it.
return false;
}

ITypeSymbol? instanceType = model.GetTypeInfo(expression).Type;
return instanceType is not null &&
instanceType.IsDisposable() &&
Expand Down

0 comments on commit 48bf08f

Please sign in to comment.