From 133908159278122a4c9042c5e6b8e9a2c8fbf812 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:00:45 +0200 Subject: [PATCH] fix: Pavex will correctly set the name of the defining crate when resolving local type aliases that refer to remote types --- libs/pavexc/src/compiler/resolvers.rs | 37 +++++++------------ .../type_alias_are_supported/diagnostics.dot | 2 +- .../expectations/app.rs | 2 +- .../expectations/diagnostics.dot | 2 +- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/libs/pavexc/src/compiler/resolvers.rs b/libs/pavexc/src/compiler/resolvers.rs index 1486de2d7..5e5fbfb91 100644 --- a/libs/pavexc/src/compiler/resolvers.rs +++ b/libs/pavexc/src/compiler/resolvers.rs @@ -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. @@ -490,7 +484,7 @@ 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 => { @@ -498,16 +492,13 @@ pub(crate) fn resolve_callable( // 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 diff --git a/libs/ui_tests/reflection/type_alias_are_supported/diagnostics.dot b/libs/ui_tests/reflection/type_alias_are_supported/diagnostics.dot index b330c4f7f..9c1567ac6 100644 --- a/libs/ui_tests/reflection/type_alias_are_supported/diagnostics.dot +++ b/libs/ui_tests/reflection/type_alias_are_supported/diagnostics.dot @@ -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 [ ] } diff --git a/libs/ui_tests/reflection/type_alias_are_supported/expectations/app.rs b/libs/ui_tests/reflection/type_alias_are_supported/expectations/app.rs index b1b600d40..a079e3065 100644 --- a/libs/ui_tests/reflection/type_alias_are_supported/expectations/app.rs +++ b/libs/ui_tests/reflection/type_alias_are_supported/expectations/app.rs @@ -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, diff --git a/libs/ui_tests/reflection/type_alias_are_supported/expectations/diagnostics.dot b/libs/ui_tests/reflection/type_alias_are_supported/expectations/diagnostics.dot index ae7fc8cce..2f6d1a385 100644 --- a/libs/ui_tests/reflection/type_alias_are_supported/expectations/diagnostics.dot +++ b/libs/ui_tests/reflection/type_alias_are_supported/expectations/diagnostics.dot @@ -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 [ ] } \ No newline at end of file