diff --git a/Directory.Packages.props b/Directory.Packages.props
index fc481f3..d3b5995 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -11,7 +11,7 @@
5.9.05.9.01.68.17
- 1.0.0-prerelease.53
+ 1.0.0-prerelease.5410.0.12
diff --git a/package.json b/package.json
index 7cc1249..29fd92c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "zodsharp",
- "version": "2.0.0-prerelease.27",
+ "version": "2.0.0-prerelease.28",
"private": true,
"license": "MIT",
"author": {
diff --git a/src/src/SourceGenerators/Helpers/CustomRuleResolver.cs b/src/src/SourceGenerators/Helpers/CustomRuleResolver.cs
index e88c1c8..aff2f78 100644
--- a/src/src/SourceGenerators/Helpers/CustomRuleResolver.cs
+++ b/src/src/SourceGenerators/Helpers/CustomRuleResolver.cs
@@ -274,7 +274,7 @@ static bool TryBuildArguments(
out string? unmappedParameterName
)
{
- arguments = new(ImmutableArray.Empty);
+ arguments = new([]);
unmappedParameterName = null;
var constructor = ruleType
diff --git a/src/src/SourceGenerators/Helpers/ExternalSchemaResolver.cs b/src/src/SourceGenerators/Helpers/ExternalSchemaResolver.cs
index 55029ce..b0aeb9e 100644
--- a/src/src/SourceGenerators/Helpers/ExternalSchemaResolver.cs
+++ b/src/src/SourceGenerators/Helpers/ExternalSchemaResolver.cs
@@ -24,19 +24,16 @@ namespace ZodSharp.SourceGenerators.Helpers;
/// the cache keys and values are value types only, so nothing from a compilation outlives the pass.
///
///
-sealed class ExternalSchemaResolver
+///
+/// Initializes a new instance of the class.
+///
+/// The compilation currently being generated.
+/// Thrown when is null.
+sealed class ExternalSchemaResolver(Compilation compilation)
{
- readonly Compilation _compilation;
+ readonly Compilation _compilation = compilation ?? throw new ArgumentNullException(nameof(compilation));
readonly ConcurrentDictionary<(TypeIdentity Type, AssemblyIdentity Assembly), Resolution> _resolved = new();
- ///
- /// Initializes a new instance of the class.
- ///
- /// The compilation currently being generated.
- /// Thrown when is null.
- public ExternalSchemaResolver(Compilation compilation) =>
- _compilation = compilation ?? throw new ArgumentNullException(nameof(compilation));
-
///
/// Determines whether the compilation currently being generated declares .
///
@@ -107,6 +104,7 @@ public bool TryGetExistingSchema(INamedTypeSymbol type, out TypeIdentity schemaT
return null;
}
+ // The schema is accessible and was generated by the assembly declaring the type.
return schema;
}
diff --git a/src/src/SourceGenerators/Helpers/TypeLibrary.cs b/src/src/SourceGenerators/Helpers/TypeLibrary.cs
index 201cd98..7a43ceb 100644
--- a/src/src/SourceGenerators/Helpers/TypeLibrary.cs
+++ b/src/src/SourceGenerators/Helpers/TypeLibrary.cs
@@ -1,7 +1,12 @@
namespace ZodSharp.SourceGenerators.Helpers;
+// Deliberately not public (the default accessibility for a top-level type): the generated type
+// library exposes Purview.SourceGeneratorFramework type identities, which the IL merge internalizes,
+// so a public spec would leave the merged analyzer with a public member whose signature references
+// an internal type. The BuildSdk generates InternalsVisibleTo for the matching unit-test assembly, so
+// tests still use it.
[GenerateTypeLibrary]
-public static partial class TypeLibraryGenerator
+static partial class TypeLibraryGenerator
{
public const string ZodSharpNamespace = "ZodSharp";
diff --git a/src/src/SourceGenerators/Helpers/ZodRefinementHookResolver.cs b/src/src/SourceGenerators/Helpers/ZodRefinementHookResolver.cs
index c08f86a..622aff4 100644
--- a/src/src/SourceGenerators/Helpers/ZodRefinementHookResolver.cs
+++ b/src/src/SourceGenerators/Helpers/ZodRefinementHookResolver.cs
@@ -75,7 +75,7 @@ internal static GeneratorResult Resolve(INamedTypeSymbol
diagnostics.Add(
ReportableDiagnostic.Create(
DiagnosticLibrary.SyncRefinementMethodRetired,
- true,
+ false,
retiredMethod.Locations.FirstOrDefault(static location => location.IsInSource)
?? GetTypeLocation(classSymbol),
retiredMethod.Name,
@@ -249,6 +249,7 @@ type is not INamedTypeSymbol named
return false;
}
+ // The RefineCtx type argument must be the same as the containing type, but the containing type may be
return SymbolEqualityComparer.Default.Equals(named.TypeArguments[0], classSymbol);
}
diff --git a/src/src/SourceGenerators/ZodSchemaAnalyzer.cs b/src/src/SourceGenerators/ZodSchemaAnalyzer.cs
index 66ba2f8..7edde34 100644
--- a/src/src/SourceGenerators/ZodSchemaAnalyzer.cs
+++ b/src/src/SourceGenerators/ZodSchemaAnalyzer.cs
@@ -241,7 +241,7 @@ ExternalSchemaResolver externalSchemas
}
}
- return reachable.ToImmutableHashSet();
+ return [.. reachable];
}
static IEnumerable EnumerateNamedTypes(INamespaceSymbol root)
diff --git a/src/src/SourceGenerators/ZodSchemaGenerator.RuleAttributes.cs b/src/src/SourceGenerators/ZodSchemaGenerator.RuleAttributes.cs
index b663567..bd9ec96 100644
--- a/src/src/SourceGenerators/ZodSchemaGenerator.RuleAttributes.cs
+++ b/src/src/SourceGenerators/ZodSchemaGenerator.RuleAttributes.cs
@@ -153,6 +153,7 @@ static string BuildInitializer(IParameterSymbol parameter)
return literal;
}
+ // If the parameter has no default value, we still need to provide an initializer for the attribute property.
return parameter.Type.IsValueType ? "default!" : "null!";
}
@@ -195,6 +196,7 @@ static bool IsSupportedAttributePropertyType(ITypeSymbol type)
if (unwrapped.ToDisplayString() == "System.Type")
return true;
+ // Only primitive types and string are supported as attribute properties.
return unwrapped.SpecialType
is SpecialType.System_Boolean
or SpecialType.System_Byte
diff --git a/src/src/ZodSharp/Core/ZodType.cs b/src/src/ZodSharp/Core/ZodType.cs
index 1f3f743..6f349fc 100644
--- a/src/src/ZodSharp/Core/ZodType.cs
+++ b/src/src/ZodSharp/Core/ZodType.cs
@@ -115,6 +115,7 @@ public ZodType Rule(TRule rule)
if (rule is null)
throw new ArgumentNullException(nameof(rule));
+ // We can safely cast to IValidationRule because TRule is constrained to that interface.
return AddRule(rule);
}
diff --git a/src/src/ZodSharp/Rules/CreditCardRule.cs b/src/src/ZodSharp/Rules/CreditCardRule.cs
index 73881d1..16f54da 100644
--- a/src/src/ZodSharp/Rules/CreditCardRule.cs
+++ b/src/src/ZodSharp/Rules/CreditCardRule.cs
@@ -28,6 +28,7 @@ public bool IsValid(in string value)
if (string.IsNullOrWhiteSpace(value))
return false;
+ // Use AsSpan to avoid allocations
return IsValid(value.AsSpan());
}
diff --git a/src/src/ZodSharp/Schemas/ZodDiscriminatedUnion.cs b/src/src/ZodSharp/Schemas/ZodDiscriminatedUnion.cs
index cdcfbf4..51a5689 100644
--- a/src/src/ZodSharp/Schemas/ZodDiscriminatedUnion.cs
+++ b/src/src/ZodSharp/Schemas/ZodDiscriminatedUnion.cs
@@ -1,4 +1,4 @@
-using System.Collections.Concurrent;
+using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Linq.Expressions;
using System.Reflection;
@@ -28,7 +28,7 @@ ImmutableDictionary> options
static readonly ConditionalWeakTable<
Type,
ConcurrentDictionary>
- > DiscriminatorAccessors = new();
+ > DiscriminatorAccessors = [];
static readonly Func