fix: empty records crashing code gen closes #728
This commit is contained in:
parent
fb967d4c7b
commit
dca09811c1
|
@ -54,7 +54,16 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
|
||||||
|(((public, opaque), (name, parameters)), constructors), span| {
|
|(((public, opaque), (name, parameters)), constructors), span| {
|
||||||
ast::UntypedDefinition::DataType(ast::DataType {
|
ast::UntypedDefinition::DataType(ast::DataType {
|
||||||
location: span,
|
location: span,
|
||||||
constructors: constructors
|
constructors: if constructors.is_empty() {
|
||||||
|
vec![ast::RecordConstructor {
|
||||||
|
location: span,
|
||||||
|
arguments: vec![],
|
||||||
|
doc: None,
|
||||||
|
name: name.clone(),
|
||||||
|
sugar: true,
|
||||||
|
}]
|
||||||
|
} else {
|
||||||
|
constructors
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mut constructor| {
|
.map(|mut constructor| {
|
||||||
if constructor.sugar {
|
if constructor.sugar {
|
||||||
|
@ -63,7 +72,8 @@ pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError
|
||||||
|
|
||||||
constructor
|
constructor
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect()
|
||||||
|
},
|
||||||
doc: None,
|
doc: None,
|
||||||
name,
|
name,
|
||||||
opaque,
|
opaque,
|
||||||
|
@ -119,4 +129,25 @@ mod tests {
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn record_sugar() {
|
||||||
|
assert_definition!(
|
||||||
|
r#"
|
||||||
|
pub type Foo {
|
||||||
|
wow: Int,
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_record_sugar() {
|
||||||
|
assert_definition!(
|
||||||
|
r#"
|
||||||
|
pub type Foo {
|
||||||
|
}
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
source: crates/aiken-lang/src/parser/definition/data_type.rs
|
||||||
|
description: "Code:\n\npub type Foo {\n}\n"
|
||||||
|
---
|
||||||
|
DataType(
|
||||||
|
DataType {
|
||||||
|
constructors: [
|
||||||
|
RecordConstructor {
|
||||||
|
location: 0..16,
|
||||||
|
name: "Foo",
|
||||||
|
arguments: [],
|
||||||
|
doc: None,
|
||||||
|
sugar: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
doc: None,
|
||||||
|
location: 0..16,
|
||||||
|
name: "Foo",
|
||||||
|
opaque: false,
|
||||||
|
parameters: [],
|
||||||
|
public: true,
|
||||||
|
typed_parameters: [],
|
||||||
|
},
|
||||||
|
)
|
|
@ -0,0 +1,39 @@
|
||||||
|
---
|
||||||
|
source: crates/aiken-lang/src/parser/definition/data_type.rs
|
||||||
|
description: "Code:\n\npub type Foo {\n wow: Int,\n}\n"
|
||||||
|
---
|
||||||
|
DataType(
|
||||||
|
DataType {
|
||||||
|
constructors: [
|
||||||
|
RecordConstructor {
|
||||||
|
location: 13..28,
|
||||||
|
name: "Foo",
|
||||||
|
arguments: [
|
||||||
|
RecordConstructorArg {
|
||||||
|
label: Some(
|
||||||
|
"wow",
|
||||||
|
),
|
||||||
|
annotation: Constructor {
|
||||||
|
location: 22..25,
|
||||||
|
module: None,
|
||||||
|
name: "Int",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
location: 17..25,
|
||||||
|
tipo: (),
|
||||||
|
doc: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
doc: None,
|
||||||
|
sugar: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
doc: None,
|
||||||
|
location: 0..28,
|
||||||
|
name: "Foo",
|
||||||
|
opaque: false,
|
||||||
|
parameters: [],
|
||||||
|
public: true,
|
||||||
|
typed_parameters: [],
|
||||||
|
},
|
||||||
|
)
|
Loading…
Reference in New Issue