Preserve TypeAlias in types for better context/feedback.
This commit is contained in:
@@ -139,7 +139,7 @@ impl Reference {
|
||||
}
|
||||
}
|
||||
|
||||
Type::Tuple { elems } => Self {
|
||||
Type::Tuple { elems, .. } => Self {
|
||||
inner: format!(
|
||||
"Tuple{elems}",
|
||||
elems = Self::from_types(elems, type_parameters)
|
||||
@@ -150,7 +150,7 @@ impl Reference {
|
||||
//
|
||||
// Implementations below are only there for completeness. In practice, we should never
|
||||
// end up creating references for 'Var' or 'Fn' in the context of blueprints.
|
||||
Type::Var { tipo } => match tipo.borrow().deref() {
|
||||
Type::Var { tipo, .. } => match tipo.borrow().deref() {
|
||||
TypeVar::Link { tipo } => Self::from_type(tipo.as_ref(), type_parameters),
|
||||
TypeVar::Generic { id } | TypeVar::Unbound { id } => {
|
||||
let tipo = type_parameters.get(id).unwrap();
|
||||
@@ -158,7 +158,7 @@ impl Reference {
|
||||
}
|
||||
},
|
||||
|
||||
Type::Fn { args, ret } => Self {
|
||||
Type::Fn { args, ret, .. } => Self {
|
||||
inner: format!(
|
||||
"Fn{args}_{ret}",
|
||||
args = Self::from_types(args, type_parameters),
|
||||
|
||||
@@ -350,7 +350,7 @@ impl Annotated<Schema> {
|
||||
annotated,
|
||||
})
|
||||
}),
|
||||
Type::Tuple { elems } => {
|
||||
Type::Tuple { elems, .. } => {
|
||||
definitions.register(type_info, &type_parameters.clone(), |definitions| {
|
||||
let elems = elems
|
||||
.iter()
|
||||
@@ -368,7 +368,7 @@ impl Annotated<Schema> {
|
||||
})
|
||||
})
|
||||
}
|
||||
Type::Var { tipo } => match tipo.borrow().deref() {
|
||||
Type::Var { tipo, .. } => match tipo.borrow().deref() {
|
||||
TypeVar::Link { tipo } => {
|
||||
Annotated::do_from_type(tipo, modules, type_parameters, definitions)
|
||||
}
|
||||
@@ -440,7 +440,7 @@ fn collect_type_parameters<'a>(
|
||||
) {
|
||||
for (index, generic) in generics.iter().enumerate() {
|
||||
match &**generic {
|
||||
Type::Var { tipo } => match *tipo.borrow() {
|
||||
Type::Var { tipo, .. } => match *tipo.borrow() {
|
||||
TypeVar::Generic { id } => {
|
||||
type_parameters.insert(
|
||||
id,
|
||||
@@ -1125,11 +1125,13 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn serialize_data_constr_1() {
|
||||
let schema = Schema::Data(Data::AnyOf(vec![Constructor {
|
||||
index: 0,
|
||||
fields: vec![],
|
||||
}
|
||||
.into()]));
|
||||
let schema = Schema::Data(Data::AnyOf(vec![
|
||||
Constructor {
|
||||
index: 0,
|
||||
fields: vec![],
|
||||
}
|
||||
.into(),
|
||||
]));
|
||||
assert_json(
|
||||
&schema,
|
||||
json!({
|
||||
@@ -1290,14 +1292,16 @@ pub mod tests {
|
||||
#[test]
|
||||
fn deserialize_any_of() {
|
||||
assert_eq!(
|
||||
Data::AnyOf(vec![Constructor {
|
||||
index: 0,
|
||||
fields: vec![
|
||||
Declaration::Referenced(Reference::new("foo")).into(),
|
||||
Declaration::Referenced(Reference::new("bar")).into()
|
||||
],
|
||||
}
|
||||
.into()]),
|
||||
Data::AnyOf(vec![
|
||||
Constructor {
|
||||
index: 0,
|
||||
fields: vec![
|
||||
Declaration::Referenced(Reference::new("foo")).into(),
|
||||
Declaration::Referenced(Reference::new("bar")).into()
|
||||
],
|
||||
}
|
||||
.into()
|
||||
]),
|
||||
serde_json::from_value(json!({
|
||||
"anyOf": [{
|
||||
"index": 0,
|
||||
@@ -1318,14 +1322,16 @@ pub mod tests {
|
||||
#[test]
|
||||
fn deserialize_one_of() {
|
||||
assert_eq!(
|
||||
Data::AnyOf(vec![Constructor {
|
||||
index: 0,
|
||||
fields: vec![
|
||||
Declaration::Referenced(Reference::new("foo")).into(),
|
||||
Declaration::Referenced(Reference::new("bar")).into()
|
||||
],
|
||||
}
|
||||
.into()]),
|
||||
Data::AnyOf(vec![
|
||||
Constructor {
|
||||
index: 0,
|
||||
fields: vec![
|
||||
Declaration::Referenced(Reference::new("foo")).into(),
|
||||
Declaration::Referenced(Reference::new("bar")).into()
|
||||
],
|
||||
}
|
||||
.into()
|
||||
]),
|
||||
serde_json::from_value(json!({
|
||||
"oneOf": [{
|
||||
"index": 0,
|
||||
|
||||
Reference in New Issue
Block a user