Skip to content

Commit 8cdfd20

Browse files
antonsyndclaude
andcommitted
chore(codegen): fix convention violations from plan implementation review
- Add TODO(#360) for ResolveExpressionTypeFromSymbols codegen-layer workaround that should be moved to the semantic phase - Use List<T>.Find() instead of LINQ FirstOrDefault() for consistency in IsEnumInstance() MemberAccess fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6ffefb6 commit 8cdfd20

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Sharpy.Compiler/CodeGen/RoslynEmitter.Expressions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ private ExpressionSyntax GenerateStringLiteral(StringLiteral literal)
239239
/// <summary>
240240
/// Fallback type resolution when SemanticInfo doesn't have an expression type recorded.
241241
/// Resolves identifiers via their symbol and member access (self.x) via the current type's fields/properties.
242+
/// TODO(#360): This is a codegen-layer workaround — move type resolution to the semantic phase.
242243
/// </summary>
243244
private SemanticType? ResolveExpressionTypeFromSymbols(Sharpy.Compiler.Parser.Ast.Expression expr)
244245
{

src/Sharpy.Compiler/CodeGen/RoslynEmitter.Operators.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,15 @@ private bool IsEnumInstance(Expression expr)
965965
var objectType = GetExpressionSemanticType(memberAccess.Object);
966966
if (objectType is Semantic.UserDefinedType objUdt && objUdt.Symbol is TypeSymbol typeSymbol)
967967
{
968-
var field = typeSymbol.Fields.FirstOrDefault(f => f.Name == memberAccess.Member);
968+
var field = typeSymbol.Fields.Find(f => f.Name == memberAccess.Member);
969969
if (field != null &&
970970
GetVariableType(field) is Semantic.UserDefinedType fieldUdt &&
971971
fieldUdt.Symbol?.TypeKind == Semantic.TypeKind.Enum)
972972
{
973973
return true;
974974
}
975975

976-
var prop = typeSymbol.Properties.FirstOrDefault(p => p.Name == memberAccess.Member);
976+
var prop = typeSymbol.Properties.Find(p => p.Name == memberAccess.Member);
977977
if (prop?.Type is Semantic.UserDefinedType propUdt &&
978978
propUdt.Symbol?.TypeKind == Semantic.TypeKind.Enum)
979979
{

0 commit comments

Comments
 (0)