Skip to content

Commit

Permalink
add dyno tests to lock in resolution of this in begin, coforall (#26025)
Browse files Browse the repository at this point in the history
This adds tests to check the behavior of resolving `this` in `begin` and
`coforall` blocks. A previous PR resolved
Cray/chapel-private#6161 as a side effect, and
this PR just adds tests for the behavior from the OP.

[reviewed by @riftEmber - thanks!]
  • Loading branch information
arezaii authored Oct 2, 2024
2 parents ffa6df5 + d07eb28 commit 328bb70
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions frontend/test/resolution/testProcThis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,83 @@ static void test1() {
assert(qt.type() == RealType::get(context, 0));
}

static void test2() {
// Test resolution of 'this' on a taskVar in begin statement
printf("test2\n");
auto config = getConfigWithHome();
Context ctx(config);
Context* context = &ctx;
ErrorGuard guard(context);
setupModuleSearchPaths(context, false, false, {}, {});

auto program = R""""(
module M {
record R { var y : int; }
proc R.this(i: int) { return this.y + i; }
var myVar = new R(42);
begin with (in myVar) {
var x = myVar[5];
}
}
)"""";
auto m = parseModule(context, std::move(program));
assert(m->numStmts() > 0);
auto begin = m->stmt(m->numStmts()-1)->toBegin();
assert(begin);
const Variable* x = begin->stmt(0)->toVariable();
assert(x);
assert(x->name() == "x");

const ResolutionResultByPostorderID& rr = resolveModule(context, m->id());

auto qt = rr.byAst(x).type();
assert(qt.type()->isIntType());
assert(!guard.realizeErrors());
}

//test resolution of 'this' on a taskVar in a coforall statement
static void test3() {
printf("test3\n");
auto config = getConfigWithHome();
Context ctx(config);
Context* context = &ctx;
ErrorGuard guard(context);
setupModuleSearchPaths(context, false, false, {}, {});

auto program = R""""(
module M {
record R { var y : int; }
proc R.this(i: int) { return this.y + i; }
var myVar = new R(42);
coforall i in 1..10 with (in myVar) {
var x = myVar[5];
}
}
)"""";
auto m = parseModule(context, std::move(program));
assert(m->numStmts() > 0);
auto coforall = m->stmt(m->numStmts()-1)->toCoforall();
assert(coforall);
const Variable* x = coforall->stmt(0)->toVariable();
assert(x);
assert(x->name() == "x");

const ResolutionResultByPostorderID& rr = resolveModule(context, m->id());

auto qt = rr.byAst(x).type();
assert(qt.type()->isIntType());

assert(!guard.realizeErrors());
}

int main() {
test1();
test2();
test3();

return 0;
}
Expand Down

0 comments on commit 328bb70

Please sign in to comment.