Skip to content

Commit 06fd945

Browse files
antonsyndclaude
andcommitted
fix: address architectural review findings from verification
- SymbolSerializer: use int.TryParse for FunctionType metadata fields to gracefully handle corrupted cache files instead of crashing - TypeChecker: replace silent Unknown return with throw in CheckBytesLiteral (bytes type must be in BuiltinRegistry) - OperatorValidator: add TODO(#559) for missing bytes comparison ops Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a819e63 commit 06fd945

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Sharpy.Compiler/Project/SymbolSerializer.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,24 @@ private static void RegisterAll()
873873
if (secondPipe >= 0)
874874
{
875875
var vStr = beforeO[(secondPipe + 1)..];
876-
paramsStr = beforeO[..secondPipe];
877-
optionalCount = int.Parse(oStr, System.Globalization.CultureInfo.InvariantCulture);
878-
variadicIndex = vStr == "-" ? null : int.Parse(vStr, System.Globalization.CultureInfo.InvariantCulture);
876+
// Use TryParse for resilience against corrupted cache files —
877+
// fall through to legacy format on failure rather than crashing.
878+
if (int.TryParse(oStr, System.Globalization.NumberStyles.Integer,
879+
System.Globalization.CultureInfo.InvariantCulture, out var parsedOptional) &&
880+
(vStr == "-" || int.TryParse(vStr, System.Globalization.NumberStyles.Integer,
881+
System.Globalization.CultureInfo.InvariantCulture, out _)))
882+
{
883+
paramsStr = beforeO[..secondPipe];
884+
optionalCount = parsedOptional;
885+
variadicIndex = vStr == "-"
886+
? null
887+
: int.Parse(vStr, System.Globalization.CultureInfo.InvariantCulture);
888+
}
889+
else
890+
{
891+
// Malformed metadata — treat as legacy format
892+
paramsStr = innerStr;
893+
}
879894
}
880895
else
881896
{

src/Sharpy.Compiler/Semantic/TypeChecker.Expressions.Literals.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,8 @@ private SemanticType CheckFStringLiteral(FStringLiteral fstr)
391391

392392
private SemanticType CheckBytesLiteral(BytesLiteralExpression bytesLit)
393393
{
394-
var bytesSymbol = _symbolTable.BuiltinRegistry.GetType(BuiltinNames.Bytes);
395-
if (bytesSymbol == null)
396-
return SemanticType.Unknown;
394+
var bytesSymbol = _symbolTable.BuiltinRegistry.GetType(BuiltinNames.Bytes)
395+
?? throw new InvalidOperationException("bytes type must be registered in BuiltinRegistry");
397396
return new UserDefinedType { Name = bytesSymbol.Name, Symbol = bytesSymbol };
398397
}
399398

src/Sharpy.Compiler/Semantic/Validation/OperatorValidator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private bool SupportsOperator(SemanticType type, string dunderName)
241241
}
242242

243243
// Bytes supports concatenation, repetition, equality, and containment
244+
// TODO(#559): bytes comparison operators (<, <=, >, >=) not yet implemented
244245
if (type is UserDefinedType { Name: BuiltinNames.Bytes })
245246
{
246247
return dunderName is DunderNames.Add or DunderNames.Mul or DunderNames.Eq or DunderNames.Ne or DunderNames.Contains;

0 commit comments

Comments
 (0)