Skip to content

Add support for multiple else if and if constexpr #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions regression-tests/pure2-nested-ifs-conditions-error.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
main: (args) =
{
a := 1;
b := 2;
c := 3;
d := 4;

{
p : *int;

// no initialization in selection_node
if args.argc > 20 {
c = 20;
} else if args.argc > 10 {
c = 10;
} else {
if args.argc % 2 {
b = 2;
} else {
b = 1;
}
}

// initialization in first if condition
if p = b& {
p = a&;
} else if args.argc == 3 {
p = b&;
if args.argc == 2 {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}

{
p : *int;

// initialization in:
// - first if branch
// - second if condition
if args.argc == 3 {
p = a&;
} else if p = b& {
p = b&;
if args.argc == 2 {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}

{
p : *int;

// initialization in:
// - first if branch
// - second if branch in nested if condition (first if)
// - else branch
if args.argc == 3 {
p = a&;
} else if args.argc == 2 {
if p = b& {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}

{
p : *int;

// initialization in:
// - first if branch
// - second if branch in nested if:
// - first branch
// - second branch in nested if condition (first if)
// - else branch
if args.argc == 3 {
p = a&;
} else if args.argc == 2 {
if b > 0 {
p = c&;
} else {
if p = b& {
p = a&;
}
else {
p = d&;
}
p* = 42;
}
p* = 24;
} else {
p = c&;
}

std::cout << p* << std::endl;
}

{
p : *int;

// initialization in:
// - first if branch
// - second if branch in nested if:
// - first branch
// - second branch in nested if:
// - first if branch
// - second if condition
// - else branch
if args.argc == 3 {
p = a&;
} else if args.argc == 2 {
if b > 0 {
p = c&;
} else {
if b > 2 {
p = a&;
}
else if p = b& {
d = p*;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}

}
27 changes: 27 additions & 0 deletions regression-tests/pure2-nested-ifs-error.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
main: (args) = {
p : *int;

a := 1;
b := 2;
c := 3;
d := 4;

if args.argc == 3 {
p = a&;
} else if b > 2 {
if args.argc == 2 {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
// p = c&;
}

std::cout << p* << std::endl;
}
52 changes: 52 additions & 0 deletions regression-tests/pure2-nested-ifs.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
main: (args) =
{
a := 1;
b := 2;
c := 3;
d := 4;

{
p : *int;

// no initialization in selection_node
if args.argc > 20 {
c = 20;
} else if args.argc > 10 {
c = 10;
} else {
if args.argc % 2 {
b = 2;
} else {
b = 1;
}
}

// initialization in:
// - first if branch
// - second if branch in nested if:
// - first branch
// - second branch in nested if:
// - first if branch
// - else branch
// - else branch
if args.argc == 3 {
p = a&;
} else if args.argc == 2 {
if b > 0 {
p = c&;
} else {
if b > 2 {
p = a&;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Loading