Scope type-aliases per module in blueprint.
Similarly to how we're already doing it for non-alias types. Fix #1074. Signed-off-by: KtorZ <5680256+KtorZ@users.noreply.github.com>
This commit is contained in:
parent
94246bdb2b
commit
58d782fa78
|
@ -193,6 +193,7 @@ impl Type {
|
|||
ret: Type::option(Type::tuple(vec![Type::prng(), a])),
|
||||
alias: Some(
|
||||
TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: FUZZER.to_string(),
|
||||
parameters: vec!["a".to_string()],
|
||||
annotation: Annotation::Fn {
|
||||
|
@ -234,6 +235,7 @@ impl Type {
|
|||
ret: Type::fuzzer(a),
|
||||
alias: Some(
|
||||
TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: SAMPLER.to_string(),
|
||||
parameters: vec!["a".to_string()],
|
||||
annotation: Annotation::Fn {
|
||||
|
@ -276,6 +278,7 @@ impl Type {
|
|||
args: vec![Type::pair(k, v)],
|
||||
alias: Some(
|
||||
TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: PAIRS.to_string(),
|
||||
parameters: vec!["k".to_string(), "v".to_string()],
|
||||
annotation: Annotation::Constructor {
|
||||
|
|
|
@ -26,6 +26,7 @@ pub use environment::collapse_links;
|
|||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TypeAliasAnnotation {
|
||||
pub module: Option<String>,
|
||||
pub alias: String,
|
||||
pub parameters: Vec<String>,
|
||||
pub annotation: Annotation,
|
||||
|
|
|
@ -1160,6 +1160,7 @@ impl<'a> Environment<'a> {
|
|||
.set_alias(Some(
|
||||
TypeAliasAnnotation {
|
||||
alias: name.to_string(),
|
||||
module: Some(module.to_string()),
|
||||
parameters: args.to_vec(),
|
||||
annotation: resolved_type.clone(),
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ impl Printer {
|
|||
alias,
|
||||
parameters,
|
||||
annotation,
|
||||
module: _,
|
||||
}) = typ.alias().as_deref()
|
||||
{
|
||||
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, typ) {
|
||||
|
@ -551,6 +552,7 @@ mod tests {
|
|||
alias: None,
|
||||
}),
|
||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: "Fuzzer".to_string(),
|
||||
parameters: vec!["a".to_string(),],
|
||||
annotation: Annotation::Fn {
|
||||
|
@ -621,6 +623,7 @@ mod tests {
|
|||
alias: None,
|
||||
}),
|
||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: "Fuzzer".to_string(),
|
||||
parameters: vec!["a".to_string(),],
|
||||
annotation: Annotation::Fn {
|
||||
|
@ -675,6 +678,7 @@ mod tests {
|
|||
alias: None,
|
||||
}),
|
||||
alias: Some(Rc::new(TypeAliasAnnotation {
|
||||
module: None,
|
||||
alias: "Identity".to_string(),
|
||||
parameters: vec!["t".to_string()],
|
||||
annotation: Annotation::Var {
|
||||
|
|
|
@ -349,12 +349,14 @@ impl Reference {
|
|||
alias,
|
||||
parameters,
|
||||
annotation,
|
||||
module,
|
||||
}) = type_info.alias().as_deref()
|
||||
{
|
||||
if let Some(resolved_parameters) = resolve_alias(parameters, annotation, type_info) {
|
||||
return Self::from_type_alias(
|
||||
type_info,
|
||||
alias.to_string(),
|
||||
alias,
|
||||
module.as_deref(),
|
||||
resolved_parameters,
|
||||
type_parameters,
|
||||
);
|
||||
|
@ -429,14 +431,20 @@ impl Reference {
|
|||
|
||||
fn from_type_alias(
|
||||
type_info: &Type,
|
||||
alias: String,
|
||||
alias: &str,
|
||||
module: Option<&str>,
|
||||
parameters: Vec<Rc<Type>>,
|
||||
type_parameters: &HashMap<u64, Rc<Type>>,
|
||||
) -> Self {
|
||||
let prefix = match module {
|
||||
Some(module) => format!("{module}/{alias}"),
|
||||
None => alias.to_string(),
|
||||
};
|
||||
|
||||
if !parameters.is_empty() {
|
||||
Reference {
|
||||
inner: format!(
|
||||
"{alias}${}",
|
||||
"{prefix}${}",
|
||||
parameters
|
||||
.iter()
|
||||
.map(|param| {
|
||||
|
@ -456,9 +464,7 @@ impl Reference {
|
|||
),
|
||||
}
|
||||
} else {
|
||||
Reference {
|
||||
inner: alias.clone(),
|
||||
}
|
||||
Reference { inner: prefix }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue