@@ -1044,6 +1044,22 @@ void BytecodeVisitor::Visit(ExprStmt& node) {
10441044 }
10451045 }
10461046
1047+ // Check if this is a builtin type method that returns void
1048+ if (!object_type.empty () && kBuiltinTypeNames .contains (object_type)) {
1049+ if (object_type == " File" ) {
1050+ if (method_name == " Open" || method_name == " Close" || method_name == " WriteLine" ||
1051+ method_name == " Seek" ) {
1052+ should_pop = false ;
1053+ }
1054+ } else if (object_type.find (" Array" ) != std::string::npos) {
1055+ if (method_name == " Add" || method_name == " RemoveAt" || method_name == " InsertAt" ||
1056+ method_name == " SetAt" || method_name == " Clear" || method_name == " Reserve" ||
1057+ method_name == " ShrinkToFit" ) {
1058+ should_pop = false ;
1059+ }
1060+ }
1061+ }
1062+
10471063 std::string method_key;
10481064 if (!object_type.empty () && !kBuiltinTypeNames .contains (object_type)) {
10491065 method_key = object_type + " ::" + method_name;
@@ -1470,6 +1486,14 @@ void BytecodeVisitor::Visit(Assign& node) {
14701486 EmitTypeConversionIfNeeded (elem_type, value_type_name);
14711487
14721488 index_access->MutableIndexExpr ().Accept (*this );
1489+
1490+ // Unwrap the index if it's a wrapper type (e.g., Int -> int)
1491+ // Array SetAt methods expect int, not Int wrapper
1492+ std::string index_type = GetTypeNameForExpr (&index_access->MutableIndexExpr ());
1493+ if (IsPrimitiveWrapper (index_type)) {
1494+ EmitCommand (" Unwrap" );
1495+ }
1496+
14731497 index_access->MutableObject ().Accept (*this );
14741498
14751499 std::string method_name = GenerateArraySetAtMethodName (array_type);
@@ -2114,6 +2138,14 @@ void BytecodeVisitor::Visit(FieldAccess& node) {
21142138
21152139void BytecodeVisitor::Visit (IndexAccess& node) {
21162140 node.MutableIndexExpr ().Accept (*this );
2141+
2142+ // Unwrap the index if it's a wrapper type (e.g., Int -> int)
2143+ // Array GetAt methods expect int, not Int wrapper
2144+ std::string index_type = GetTypeNameForExpr (&node.MutableIndexExpr ());
2145+ if (IsPrimitiveWrapper (index_type)) {
2146+ EmitCommand (" Unwrap" );
2147+ }
2148+
21172149 node.MutableObject ().Accept (*this );
21182150
21192151 std::string array_type = GetTypeNameForExpr (&node.MutableObject ());
@@ -2675,6 +2707,31 @@ BytecodeVisitor::OperandType BytecodeVisitor::DetermineOperandType(Expr* expr) {
26752707 }
26762708 }
26772709
2710+ if (auto * index_access = dynamic_cast <IndexAccess*>(expr)) {
2711+ // Get the element type of the array
2712+ std::string array_type = GetTypeNameForExpr (&index_access->MutableObject ());
2713+ std::string elem_type = GetElementTypeForArray (array_type);
2714+
2715+ if (elem_type == " int" ) {
2716+ return OperandType::kInt ;
2717+ }
2718+ if (elem_type == " float" ) {
2719+ return OperandType::kFloat ;
2720+ }
2721+ if (elem_type == " byte" ) {
2722+ return OperandType::kByte ;
2723+ }
2724+ if (elem_type == " bool" ) {
2725+ return OperandType::kBool ;
2726+ }
2727+ if (elem_type == " char" ) {
2728+ return OperandType::kChar ;
2729+ }
2730+ if (elem_type == " String" ) {
2731+ return OperandType::kString ;
2732+ }
2733+ }
2734+
26782735 if (auto * binary = dynamic_cast <Binary*>(expr)) {
26792736 OperandType lhs_type = DetermineOperandType (&binary->MutableLhs ());
26802737 OperandType rhs_type = DetermineOperandType (&binary->MutableRhs ());
@@ -2904,7 +2961,7 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
29042961 return " String" ;
29052962 }
29062963 if (ns_name == " ReadChar" && call->Args ().size () == 0 ) {
2907- return " Char " ;
2964+ return " char " ;
29082965 }
29092966 // Time and Date Operations
29102967 if (ns_name == " FormatDateTime" && call->Args ().size () == 2 ) {
@@ -2924,16 +2981,16 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
29242981 return " Bool" ;
29252982 }
29262983 if (ns_name == " DeleteFile" && call->Args ().size () == 1 ) {
2927- return " Bool " ;
2984+ return " bool " ;
29282985 }
29292986 if (ns_name == " DeleteDirectory" && call->Args ().size () == 1 ) {
2930- return " Bool " ;
2987+ return " bool " ;
29312988 }
29322989 if (ns_name == " MoveFile" && call->Args ().size () == 2 ) {
2933- return " Bool " ;
2990+ return " bool " ;
29342991 }
29352992 if (ns_name == " CopyFile" && call->Args ().size () == 2 ) {
2936- return " Bool " ;
2993+ return " bool " ;
29372994 }
29382995 if (ns_name == " ListDirectory" && call->Args ().size () == 1 ) {
29392996 return " StringArray" ;
@@ -2942,7 +2999,7 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
29422999 return " String" ;
29433000 }
29443001 if (ns_name == " ChangeDirectory" && call->Args ().size () == 1 ) {
2945- return " Bool " ;
3002+ return " bool " ;
29463003 }
29473004 // Process Control
29483005 if (ns_name == " Sleep" && call->Args ().size () == 1 ) {
@@ -2961,7 +3018,7 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
29613018 return " String?" ; // Returns Nullable<String>
29623019 }
29633020 if (ns_name == " SetEnvironmentVar" && call->Args ().size () == 2 ) {
2964- return " Bool " ;
3021+ return " bool " ;
29653022 }
29663023 // Random Number Generation
29673024 if (ns_name == " SeedRandom" && call->Args ().size () == 1 ) {
@@ -3019,6 +3076,17 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
30193076 if (method_name == " GetHash" ) {
30203077 return " int" ;
30213078 }
3079+ if (method_name == " Equals" ) {
3080+ return " bool" ;
3081+ }
3082+ if (method_name == " IsLess" ) {
3083+ return " bool" ;
3084+ }
3085+ if (method_name == " Add" || method_name == " RemoveAt" || method_name == " InsertAt" ||
3086+ method_name == " SetAt" || method_name == " Clear" || method_name == " Reserve" ||
3087+ method_name == " ShrinkToFit" ) {
3088+ return " void" ;
3089+ }
30223090 }
30233091 // Handle String methods
30243092 if (object_type == " String" ) {
@@ -3034,6 +3102,12 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
30343102 if (method_name == " ToUtf8Bytes" ) {
30353103 return " ByteArray" ;
30363104 }
3105+ if (method_name == " Equals" ) {
3106+ return " bool" ;
3107+ }
3108+ if (method_name == " IsLess" ) {
3109+ return " bool" ;
3110+ }
30373111 }
30383112 // Handle wrapper type methods (Int, Float, etc.)
30393113 if (method_name == " ToString" ) {
@@ -3042,6 +3116,30 @@ std::string BytecodeVisitor::GetTypeNameForExpr(Expr* expr) {
30423116 if (method_name == " GetHash" ) {
30433117 return " int" ;
30443118 }
3119+ if (method_name == " Equals" ) {
3120+ return " bool" ;
3121+ }
3122+ if (method_name == " IsLess" ) {
3123+ return " bool" ;
3124+ }
3125+ // Handle File methods
3126+ if (object_type == " File" ) {
3127+ if (method_name == " Open" || method_name == " Close" || method_name == " WriteLine" || method_name == " Seek" ) {
3128+ return " void" ;
3129+ }
3130+ if (method_name == " IsOpen" || method_name == " Eof" ) {
3131+ return " bool" ;
3132+ }
3133+ if (method_name == " Read" ) {
3134+ return " ByteArray" ;
3135+ }
3136+ if (method_name == " ReadLine" ) {
3137+ return " String" ;
3138+ }
3139+ if (method_name == " Tell" || method_name == " Write" ) {
3140+ return " int" ;
3141+ }
3142+ }
30453143 }
30463144
30473145 // Handle method calls on user-defined types
0 commit comments