Skip to content
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

Fix dyno resolving dependently-typed fields in method #25932

Merged
merged 4 commits into from
Sep 24, 2024
Merged
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
7 changes: 2 additions & 5 deletions frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,16 +1632,13 @@ QualifiedType getInstantiationType(Context* context,

// which BasicClassType to use?
const BasicClassType* bct;
if (auto formalBct = formalCt->basicClassType()) {
auto formalBct = formalCt->basicClassType();
if (formalBct && getTypeGenericity(context, formalBct) == Type::CONCRETE) {
bct = formalBct;
} else {
CHPL_ASSERT(formalCt->manageableType()->toManageableType());
bct = actualCt->basicClassType();
}
auto g = getTypeGenericity(context, bct);
if (g != Type::CONCRETE) {
CHPL_UNIMPL("instantiate generic class formal");
}

// now construct the ClassType
auto ct = ClassType::get(context, bct, manager, dec);
Expand Down
33 changes: 33 additions & 0 deletions frontend/test/resolution/testClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,44 @@ static void test3() {
assert(qt.type()->toIntType()->bitwidth() == 64);
}

// Test resolving dependently-typed field usage in method body
static void test4() {
printf("test4\n");

Context ctx;
auto context = &ctx;
ErrorGuard guard(context);

std::string program = R"""(
class Bar {
param rank : int;
var myTup : rank*int;

proc getSomething() {
return myTup;
}
}

var b = new Bar(2);
var x = b.getSomething();
)""";

auto m = parseModule(context, program);
auto r = resolveModule(context, m->id());

auto x = findVariable(m, "x");
auto qt = r.byAst(x).type();
assert(qt.type()->isTupleType());
assert(qt.type()->toTupleType()->numElements() == 2);
assert(qt.type()->toTupleType()->starType().type());
assert(qt.type()->toTupleType()->starType().type()->isIntType());
}

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

return 0;
}