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 UDT re-exports #2137

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions compiler/qsc_frontend/src/compile/tests/multiple_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,39 @@ fn aliased_export_via_aliased_import() {
),
]);
}

#[test]
fn udt_reexport() {
multiple_package_check(vec![
(
"A",
"struct Foo { content: Bool }
export Foo as Bar;",
),
(
"B",
" @EntryPoint()
operation Main() : Unit {
let x = new A.A.Bar { content = true };
}",
),
]);
}

#[test]
fn callable_reexport() {
multiple_package_check(vec![
(
"A",
"function Foo() : Unit { }
export Foo as Bar;",
),
(
"B",
" @EntryPoint()
operation Main() : Unit {
let x = A.A.Bar();
}",
),
]);
}
8 changes: 4 additions & 4 deletions compiler/qsc_frontend/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,10 @@ impl GlobalTable {
.insert_or_find_namespace(ns.iter().map(|s| s.name.clone()));
}
hir::ItemKind::Ty(..) => {
self.scope
.tys
.get_mut_or_default(namespace)
.insert(global.name.clone(), Res::ExportedItem(item_id, None));
self.scope.tys.get_mut_or_default(namespace).insert(
global.name.clone(),
Res::Item(item_id, ItemStatus::Available),
);
}
hir::ItemKind::Export(_, _) => {
unreachable!("find_item will never return an Export")
Expand Down
11 changes: 5 additions & 6 deletions compiler/qsc_frontend/src/typeck/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ pub(super) fn ty_from_path(names: &Names, path: &Path) -> Ty {
// So realistically, by construction, `Param` here is unreachable.
// A path can also never resolve to an export, because in typeck/check,
// we resolve exports to their original definition.
Some(
resolve::Res::Local(_) | resolve::Res::Param { .. } | resolve::Res::ExportedItem(_, _),
) => {
unreachable!(
"A path should never resolve \
Some(resolve::Res::Local(_) | resolve::Res::Param { .. }) => unreachable!(
" A path should never resolve \
to a local or a parameter, as there is syntactic differentiation."
)
),
Some(resolve::Res::ExportedItem(item_id, alias)) => {
unreachable!("Exported items should have been resolved to their original definition in type checking. Found {:?} with alias {:?}", item_id, alias);
}
None => Ty::Err,
}
Expand Down