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: Pavex will correctly set the name of the defining crate when resolving local type aliases that refer to remote types #356

Merged
merged 2 commits into from
Oct 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
8 changes: 8 additions & 0 deletions libs/pavex_test_runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,14 @@ fn code_generation_test(
}
};

if std::env::var("PAVEX_LOG").as_deref() == Ok("true") {
eprintln!(
"Code generation stderr:\n{}Code generation stdout:\n{}",
textwrap::indent(&codegen_output.stderr, " "),
textwrap::indent(&codegen_output.stdout, " "),
)
}

let expectations_directory = test.expectations_directory();
let outcome = if !output.status.success() {
match test.configuration.expectations.codegen {
Expand Down
37 changes: 14 additions & 23 deletions libs/pavexc/src/compiler/resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,12 @@ pub(crate) fn resolve_callable(
Some((parent, parent_path)) => {
match krate_collection.get_canonical_path_by_global_type_id(&parent.item_id) {
Ok(canonical_segments) => {
let segments =
canonical_segments
.into_iter()
.skip(1)
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
});
// We use the first segment from the original path, since that's been resolved to the name of the defining crate
// and we want to keep that information.
let mut segments: Vec<_> = std::iter::once(parent_path.segments[0].clone())
.chain(segments)
let mut segments: Vec<_> = canonical_segments
.into_iter()
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
})
.collect();
// The canonical path doesn't include the (populated or omitted) generic arguments from the user-provided path,
// so we need to add them back in.
Expand Down Expand Up @@ -490,24 +484,21 @@ pub(crate) fn resolve_callable(
ResolvedPath {
segments,
qualified_self: callable_path.qualified_self.clone(),
package_id: callable_path.package_id.clone(),
package_id: p.package_id.clone(),
}
}
None => {
// There was no parent, it's a free function or a straight struct/enum. We need to go through the same process
// we applied for the parent.
match krate_collection.get_canonical_path_by_global_type_id(&callable.item_id) {
Ok(p) => {
let segments = p.into_iter().skip(1).map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
});
// We use the first segment from the original callable path, since that's been resolved to the defining crate
// and we want to keep that information.
let mut segments: Vec<_> =
std::iter::once(callable_path.segments[0].clone())
.chain(segments)
.collect();
let mut segments: Vec<_> = p
.into_iter()
.map(|s| ResolvedPathSegment {
ident: s.into(),
generic_arguments: vec![],
})
.collect();
// The canonical path doesn't include the (populated or omitted) generic arguments from the user-provided callable path,
// so we need to add them back in.
segments.last_mut().unwrap().generic_arguments = callable_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ digraph "* /home - 1" {
digraph app_state {
0 [ label = "crate::ApplicationState((bool, char, u8), dep_f8f62968::ActualType) -> crate::ApplicationState"]
1 [ label = "app_f8f62968::constructor_with_output_tuple() -> (bool, char, u8)"]
2 [ label = "app_f8f62968::RemoteAlias::new() -> dep_f8f62968::ActualType"]
2 [ label = "dep_f8f62968::ActualType::new() -> dep_f8f62968::ActualType"]
2 -> 0 [ ]
1 -> 0 [ ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct ApplicationState {
s1: dep_f8f62968::ActualType,
}
pub async fn build_application_state() -> crate::ApplicationState {
let v0 = app::RemoteAlias::new();
let v0 = dep_f8f62968::ActualType::new();
let v1 = app::constructor_with_output_tuple();
crate::ApplicationState {
s0: v1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ digraph "* /home - 1" {
digraph app_state {
0 [ label = "crate::ApplicationState((bool, char, u8), dep_f8f62968::ActualType) -> crate::ApplicationState"]
1 [ label = "app::constructor_with_output_tuple() -> (bool, char, u8)"]
2 [ label = "app::RemoteAlias::new() -> dep_f8f62968::ActualType"]
2 [ label = "dep_f8f62968::ActualType::new() -> dep_f8f62968::ActualType"]
2 -> 0 [ ]
1 -> 0 [ ]
}