Skip to content

Commit 8e7f9db

Browse files
committed
Use assertions for compiler option preconditions
Treat the compiler options snapshot as an internal contract: the only producer normalizes null define symbols before construction. Use the project's assertion convention for that programmer error and keep the remaining tests focused on snapshot behavior.
1 parent b8ae2d6 commit 8e7f9db

2 files changed

Lines changed: 2 additions & 15 deletions

File tree

Assets/Tests/Editor/DynamicCodeToolTests/RoslynCompilerOptionsTests.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,5 @@ public void Constructor_WithEmptyDefineSymbols_CapturesEmptySnapshot()
4747
Assert.That(options.AllowUnsafeCode, Is.False);
4848
}
4949

50-
/// <summary>
51-
/// Verifies a null define-symbol collection fails fast at the snapshot boundary.
52-
/// </summary>
53-
[Test]
54-
public void Constructor_WithNullDefineSymbols_ThrowsArgumentNullException()
55-
{
56-
Assert.That(
57-
() => new RoslynCompilerOptions(null, false),
58-
Throws.ArgumentNullException);
59-
}
6050
}
6151
}

Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/RoslynCompilerOptions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
21
using System.Collections.Generic;
2+
using UnityEngine;
33

44
namespace io.github.hatayama.UnityCliLoop.FirstPartyTools
55
{
@@ -19,10 +19,7 @@ public RoslynCompilerOptions(
1919
IReadOnlyCollection<string> defineSymbols,
2020
bool allowUnsafeCode)
2121
{
22-
if (defineSymbols == null)
23-
{
24-
throw new ArgumentNullException(nameof(defineSymbols));
25-
}
22+
Debug.Assert(defineSymbols != null, "defineSymbols must not be null");
2623

2724
List<string> filteredDefineSymbols = new(defineSymbols.Count);
2825
foreach (string defineSymbol in defineSymbols)

0 commit comments

Comments
 (0)