Omit validator return annotation when formatting
Unless it is NOT bool as it deviates from the default and while wrong, we want to preserve it to provide a good error.
This commit is contained in:
parent
d74e36d0bc
commit
ee8f608c0b
|
@ -536,7 +536,14 @@ impl<'comments> Formatter<'comments> {
|
|||
|
||||
// Add return annotation
|
||||
let head = match return_annotation {
|
||||
Some(anno) => head.append(" -> ").append(self.annotation(anno)),
|
||||
Some(anno) => {
|
||||
let is_bool = anno.is_logically_equal(&Annotation::boolean(Span::empty()));
|
||||
if is_validator && is_bool {
|
||||
head
|
||||
} else {
|
||||
head.append(" -> ").append(self.annotation(anno))
|
||||
}
|
||||
}
|
||||
None => head,
|
||||
}
|
||||
.group();
|
||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
|||
location: 20..44,
|
||||
name: "spend",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 26..44,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 58,
|
||||
on_test_failure: FailImmediately,
|
||||
|
@ -99,7 +106,14 @@ Validator(
|
|||
location: 63..79,
|
||||
name: "mint",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 68..79,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 93,
|
||||
on_test_failure: FailImmediately,
|
||||
|
@ -113,27 +127,34 @@ Validator(
|
|||
UntypedArg {
|
||||
by: ByName(
|
||||
Discarded {
|
||||
name: "_ctx",
|
||||
label: "_ctx",
|
||||
location: 0..0,
|
||||
name: "_",
|
||||
label: "_",
|
||||
location: 0..9,
|
||||
},
|
||||
),
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
annotation: None,
|
||||
doc: None,
|
||||
is_validator_param: false,
|
||||
},
|
||||
],
|
||||
body: ErrorTerm {
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
},
|
||||
doc: None,
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
name: "else",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 0..9,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 95,
|
||||
end_position: 8,
|
||||
on_test_failure: FailImmediately,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
|||
location: 20..44,
|
||||
name: "spend",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 26..44,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 58,
|
||||
on_test_failure: FailImmediately,
|
||||
|
@ -99,7 +106,14 @@ Validator(
|
|||
location: 63..79,
|
||||
name: "mint",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 68..79,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 93,
|
||||
on_test_failure: FailImmediately,
|
||||
|
@ -131,7 +145,14 @@ Validator(
|
|||
location: 103..106,
|
||||
name: "else",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 103..106,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 120,
|
||||
on_test_failure: FailImmediately,
|
||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
|||
location: 20..44,
|
||||
name: "spend",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 26..44,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 58,
|
||||
on_test_failure: FailImmediately,
|
||||
|
@ -71,27 +78,34 @@ Validator(
|
|||
UntypedArg {
|
||||
by: ByName(
|
||||
Discarded {
|
||||
name: "_ctx",
|
||||
label: "_ctx",
|
||||
location: 0..0,
|
||||
name: "_",
|
||||
label: "_",
|
||||
location: 0..9,
|
||||
},
|
||||
),
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
annotation: None,
|
||||
doc: None,
|
||||
is_validator_param: false,
|
||||
},
|
||||
],
|
||||
body: ErrorTerm {
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
},
|
||||
doc: None,
|
||||
location: 0..0,
|
||||
location: 0..9,
|
||||
name: "else",
|
||||
public: true,
|
||||
return_annotation: None,
|
||||
return_annotation: Some(
|
||||
Constructor {
|
||||
location: 0..9,
|
||||
module: None,
|
||||
name: "Bool",
|
||||
arguments: [],
|
||||
},
|
||||
),
|
||||
return_type: (),
|
||||
end_position: 60,
|
||||
end_position: 8,
|
||||
on_test_failure: FailImmediately,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -112,7 +112,7 @@ fn bls12_381_ml_result_in_data_type() {
|
|||
fn validator_illegal_return_type() {
|
||||
let source_code = r#"
|
||||
validator foo {
|
||||
spend(d, r, c) {
|
||||
spend(d, r, c) -> Int {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,16 @@ source: crates/aiken-lang/src/tests/format.rs
|
|||
description: "Code:\n\n validator foo( param1 : ByteArray ) {\n spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\nmint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
||||
---
|
||||
validator foo(param1: ByteArray) {
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
|
||||
/// This is bar
|
||||
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
mint(r: Redeemer, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,16 +3,16 @@ source: crates/aiken-lang/src/tests/format.rs
|
|||
description: "Code:\n\n validator foo ( param1 : ByteArray ) {\n spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {\n True\n }\n /// This is bar\nmint(r: Redeemer, ctx : ScriptContext ) -> Bool { True }\n }\n"
|
||||
---
|
||||
validator foo(param1: ByteArray) {
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
|
||||
/// This is bar
|
||||
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
mint(r: Redeemer, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ description: "Code:\n\nvalidator thing ( ) {\n// What is the purpose of life\n\n
|
|||
validator thing {
|
||||
// What is the purpose of life
|
||||
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||
True
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,9 @@ validator foo {
|
|||
Void
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
// I am lost
|
||||
}
|
||||
|
||||
// I am lost
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ validator foo(Foo { a, b, .. }) {
|
|||
todo
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ validator foo([Bar]: List<Bar>) {
|
|||
todo
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ validator foo((Baz, Baz) as x) {
|
|||
todo
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ validator fiz((fst, snd) as x: Pair<Int, Int>) {
|
|||
todo
|
||||
}
|
||||
|
||||
else(_ctx) {
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue