Skip to content

Commit

Permalink
expand test cases for owned and _owned passing
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmad Rezaii <[email protected]>
  • Loading branch information
arezaii committed Aug 27, 2024
1 parent eb2c554 commit e7ee7c4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions frontend/test/resolution/testClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,19 @@ static void test4() {
setupModuleSearchPaths(context, false, false, {}, {});

std::string program = R"""(
class C { var y : int; }
proc foo(arg: _owned) {
}
// compiler-generate 'borrow' method
class C { var y : int; }
proc bar(arg: owned) {
}
proc baz(type arg: _owned(C)) {
}
proc buz(type arg: owned C) {
}
var obj = new C(5);
var x = obj.borrow();
Expand All @@ -182,6 +190,9 @@ static void test4() {
var obj4 = new C(42);
foo(obj4);
bar(obj4);
baz(obj4.type);
buz(obj4.type);
)""";

Expand All @@ -191,19 +202,18 @@ static void test4() {
auto init = var->initExpression();
assert(init);
auto qt = results.byAst(init).type();
auto c = m->stmt(2)->toClass();
auto c = m->stmt(0)->toClass();
assert(c);
auto it = initialTypeForTypeDecl(context, c->id());
auto bct = it->getCompositeType()->toBasicClassType();
assert(bct);

auto borrowedNonNil = ClassType::get(context, bct, nullptr,
ClassTypeDecorator(
ClassTypeDecorator::BORROWED_NONNIL));
ClassTypeDecorator::BORROWED_NONNIL));

assert(qt.type() == borrowedNonNil);

assert(guard.numErrors() == 0);
assert(guard.realizeErrors() == 0);
}

// test that we can map _shared to shared
Expand Down

0 comments on commit e7ee7c4

Please sign in to comment.