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

Dyno fix forwarding with except excluding other symbols #25931

Merged
merged 2 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: 6 additions & 1 deletion frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,12 @@ static void helpSetFieldTypes(const CompositeType* ct,
if (fwdTo->isDecl()) {
helpSetFieldTypes(ct, fwd->expr(), r, initedInParent, fields, syntaxOnly);
}
fields.addForwarding(fwd->id(), r.byAst(fwdTo).type());
// If it's a visibility clause, use the type of the symbol rather than
// the whole clause.
auto fwdToSymbol = fwdTo->isVisibilityClause()
? fwdTo->toVisibilityClause()->symbol()
: fwdTo;
fields.addForwarding(fwd->id(), r.byAst(fwdToSymbol).type());
}
}

Expand Down
40 changes: 40 additions & 0 deletions frontend/test/resolution/testForwarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,44 @@ static void test7() {
guard.realizeErrors();
}

// Test that 'except' clause doesn't exclude other symbols.
// Doesn't test 'except' correct exclusion functionality.
static void test8() {
printf("test8\n");

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

const char* contents =
R""""(
module M {
record Foo {
var _instance : owned Bar;

proc init(value) {
this._instance = value;
}

proc arbitrarySymbol do return 4;
forwarding _instance except arbitrarySymbol;
}

class Bar {
var asdf : int;
}

var myFoo = new Foo(new unmanaged Bar());
var x = myFoo.asdf;
}
)"""";

auto qt = resolveQualifiedTypeOfX(context, contents);
assert(qt.type()->isIntType());

guard.realizeErrors();
}


int main() {
test1();
Expand All @@ -513,6 +551,8 @@ int main() {

// TODO: forwarding with only, except

test8();

return 0;
}