Skip to content

Commit

Permalink
[main] Fix args indexing in C++.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfusik committed Nov 6, 2023
1 parent c6d3549 commit c34bbe7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions GenCpp.fu
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ public class GenCpp : GenCCpp
switch (klass.Class.Id) {
case FuId.ArrayStorageClass:
if (klass.Id == FuId.MainArgsType) {
Include("string_view");
Write("std::string_view(");
WriteArgsIndexing(expr.Right);
WriteChar(')');
return;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions libfut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13020,7 +13020,10 @@ void GenCpp::writeIndexingExpr(const FuBinaryExpr * expr, FuPriority parent)
switch (klass->class_->id) {
case FuId::arrayStorageClass:
if (klass->id == FuId::mainArgsType) {
include("string_view");
write("std::string_view(");
writeArgsIndexing(expr->right.get());
writeChar(')');
return;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions libfut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13384,7 +13384,10 @@ protected override void WriteIndexingExpr(FuBinaryExpr expr, FuPriority parent)
switch (klass.Class.Id) {
case FuId.ArrayStorageClass:
if (klass.Id == FuId.MainArgsType) {
Include("string_view");
Write("std::string_view(");
WriteArgsIndexing(expr.Right);
WriteChar(')');
return;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions libfut.js
Original file line number Diff line number Diff line change
Expand Up @@ -13808,7 +13808,10 @@ export class GenCpp extends GenCCpp
switch (klass.class.id) {
case FuId.ARRAY_STORAGE_CLASS:
if (klass.id == FuId.MAIN_ARGS_TYPE) {
this.include("string_view");
this.write("std::string_view(");
this.writeArgsIndexing(expr.right);
this.writeChar(41);
return;
}
break;
Expand Down
2 changes: 1 addition & 1 deletion test/MainArgs.fu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public static class Runner
{
public static int Main(string[] args) //FAIL: cl
{
if (args.Length == 2 && args[0] == "foo" && args[1] == "bar") { //FAIL: cpp swift TODO
if (args.Length == 2 && args[0] == "foo" && args[1] == "bar") { //FAIL: swift TODO
int i = 0;
foreach (string arg in args) {
if (arg != (i == 0 ? "foo" : "bar"))
Expand Down

0 comments on commit c34bbe7

Please sign in to comment.