Skip to content

Commit

Permalink
Merge #102: Fix type alias
Browse files Browse the repository at this point in the history
4a18efe fix: Parse type aliases (Christian Lewe)
720e294 chore: Update old test case (Christian Lewe)

Pull request description:

  Type aliases didn't parse as expected. This PR fixes that.

ACKs for top commit:
  apoelstra:
    ACK 4a18efe; successfully ran local tests

Tree-SHA512: 773a54c7d1912d6bceb5473e58f62fd5fcc18a6b24054ee5ddd28ba90917ed19fbaff377afc87eaee16d406bd4acccdba9d1b35e51348dbcd1cae8901254a15f
  • Loading branch information
apoelstra committed Dec 10, 2024
2 parents 980a2e1 + 4a18efe commit 3a0499a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod tests {
}
fn main() {
jet_verify(my_true());
assert!(my_true());
}
"#;
match SatisfiedProgram::new(prog_text, Arguments::default(), WitnessValues::default()) {
Expand All @@ -552,11 +552,6 @@ fn main() {
}
}

#[test]
fn fuzz_regression_1() {
parse::Program::parse_from_str("type f=f").unwrap();
}

#[test]
fn fuzz_regression_2() {
parse::Program::parse_from_str("fn dbggscas(h: bool, asyxhaaaa: a) {\nfalse}\n\n").unwrap();
Expand All @@ -567,4 +562,18 @@ fn main() {
fn fuzz_slow_unit_1() {
parse::Program::parse_from_str("fn fnnfn(MMet:(((sssss,((((((sssss,ssssss,ss,((((((sssss,ss,((((((sssss,ssssss,ss,((((((sssss,ssssss,((((((sssss,sssssssss,(((((((sssss,sssssssss,(((((ssss,((((((sssss,sssssssss,(((((((sssss,ssss,((((((sssss,ss,((((((sssss,ssssss,ss,((((((sssss,ssssss,((((((sssss,sssssssss,(((((((sssss,sssssssss,(((((ssss,((((((sssss,sssssssss,(((((((sssss,sssssssssssss,(((((((((((u|(").unwrap_err();
}

#[test]
fn type_alias() {
let prog_text = r#"type MyAlias = u32;
fn main() {
let x: MyAlias = 32;
assert!(jet::eq_32(x, 32));
}
"#;
TestCase::program_text(Cow::Borrowed(prog_text))
.with_witness_values(WitnessValues::default())
.assert_run_success();
}
}
2 changes: 1 addition & 1 deletion src/minimal.pest
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ty = { alias_name | builtin_alias | sum_type | option_type | boo
builtin_alias = @{ "Ctx8" | "Pubkey" | "Message64" | "Message" | "Signature" | "Scalar" | "Fe" | "Gej" | "Ge" | "Point" | "Height" | "Time" | "Distance" | "Duration" | "Lock" | "Outpoint" | "Confidential1" | "ExplicitAsset" | "Asset1" | "ExplicitAmount" | "Amount1" | "ExplicitNonce" | "Nonce" | "TokenAmount1" }
alias_name = { !builtin_alias ~ identifier }
type_keyword = @{ "type" ~ !ASCII_ALPHANUMERIC }
type_alias = { type_keyword ~ alias_name ~ "=" ~ ty }
type_alias = { type_keyword ~ alias_name ~ "=" ~ ty ~ ";" }

left_expr = { "Left(" ~ expression ~ ")" }
right_expr = { "Right(" ~ expression ~ ")" }
Expand Down
2 changes: 1 addition & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl fmt::Display for Item {

impl fmt::Display for TypeAlias {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "type {} = {}", self.name(), self.ty())
write!(f, "type {} = {};", self.name(), self.ty())
}
}

Expand Down

0 comments on commit 3a0499a

Please sign in to comment.