Skip to content

Commit a819e63

Browse files
antonsyndclaude
andcommitted
fix(semantic): add bytes integer indexing type inference
Bytes indexing (b[0]) was returning UnknownType because the __getitem__ protocol stub lacks return type information. Add explicit bytes case in InferIndexAccessType (matching the existing str pattern) to return int, consistent with Python's bytes[int] → int behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8ce7a7b commit a819e63

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Sharpy.Compiler/Semantic/TypeInferenceService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,12 @@ c.Parameters[1].Type is GenericType paramGeneric &&
779779
return SemanticType.Str;
780780
}
781781

782+
// Bytes - integer indexing returns int (b[0] → 104)
783+
if (container is UserDefinedType { Name: BuiltinNames.Bytes })
784+
{
785+
return SemanticType.Int;
786+
}
787+
782788
// User-defined types with __getitem__
783789
TypeSymbol? typeSymbol = container switch
784790
{

0 commit comments

Comments
 (0)