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
|
// Add return annotation
|
||||||
let head = match 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,
|
None => head,
|
||||||
}
|
}
|
||||||
.group();
|
.group();
|
||||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
||||||
location: 20..44,
|
location: 20..44,
|
||||||
name: "spend",
|
name: "spend",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 26..44,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 58,
|
end_position: 58,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
@ -99,7 +106,14 @@ Validator(
|
||||||
location: 63..79,
|
location: 63..79,
|
||||||
name: "mint",
|
name: "mint",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 68..79,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 93,
|
end_position: 93,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
@ -113,27 +127,34 @@ Validator(
|
||||||
UntypedArg {
|
UntypedArg {
|
||||||
by: ByName(
|
by: ByName(
|
||||||
Discarded {
|
Discarded {
|
||||||
name: "_ctx",
|
name: "_",
|
||||||
label: "_ctx",
|
label: "_",
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
annotation: None,
|
annotation: None,
|
||||||
doc: None,
|
doc: None,
|
||||||
is_validator_param: false,
|
is_validator_param: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
body: ErrorTerm {
|
body: ErrorTerm {
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
},
|
},
|
||||||
doc: None,
|
doc: None,
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
name: "else",
|
name: "else",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 0..9,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 95,
|
end_position: 8,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
||||||
location: 20..44,
|
location: 20..44,
|
||||||
name: "spend",
|
name: "spend",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 26..44,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 58,
|
end_position: 58,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
@ -99,7 +106,14 @@ Validator(
|
||||||
location: 63..79,
|
location: 63..79,
|
||||||
name: "mint",
|
name: "mint",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 68..79,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 93,
|
end_position: 93,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
@ -131,7 +145,14 @@ Validator(
|
||||||
location: 103..106,
|
location: 103..106,
|
||||||
name: "else",
|
name: "else",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 103..106,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 120,
|
end_position: 120,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
|
|
@ -57,7 +57,14 @@ Validator(
|
||||||
location: 20..44,
|
location: 20..44,
|
||||||
name: "spend",
|
name: "spend",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 26..44,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 58,
|
end_position: 58,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
|
@ -71,27 +78,34 @@ Validator(
|
||||||
UntypedArg {
|
UntypedArg {
|
||||||
by: ByName(
|
by: ByName(
|
||||||
Discarded {
|
Discarded {
|
||||||
name: "_ctx",
|
name: "_",
|
||||||
label: "_ctx",
|
label: "_",
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
annotation: None,
|
annotation: None,
|
||||||
doc: None,
|
doc: None,
|
||||||
is_validator_param: false,
|
is_validator_param: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
body: ErrorTerm {
|
body: ErrorTerm {
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
},
|
},
|
||||||
doc: None,
|
doc: None,
|
||||||
location: 0..0,
|
location: 0..9,
|
||||||
name: "else",
|
name: "else",
|
||||||
public: true,
|
public: true,
|
||||||
return_annotation: None,
|
return_annotation: Some(
|
||||||
|
Constructor {
|
||||||
|
location: 0..9,
|
||||||
|
module: None,
|
||||||
|
name: "Bool",
|
||||||
|
arguments: [],
|
||||||
|
},
|
||||||
|
),
|
||||||
return_type: (),
|
return_type: (),
|
||||||
end_position: 60,
|
end_position: 8,
|
||||||
on_test_failure: FailImmediately,
|
on_test_failure: FailImmediately,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -112,7 +112,7 @@ fn bls12_381_ml_result_in_data_type() {
|
||||||
fn validator_illegal_return_type() {
|
fn validator_illegal_return_type() {
|
||||||
let source_code = r#"
|
let source_code = r#"
|
||||||
validator foo {
|
validator foo {
|
||||||
spend(d, r, c) {
|
spend(d, r, c) -> Int {
|
||||||
1
|
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"
|
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) {
|
validator foo(param1: ByteArray) {
|
||||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is bar
|
/// This is bar
|
||||||
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
mint(r: Redeemer, ctx: ScriptContext) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
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"
|
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) {
|
validator foo(param1: ByteArray) {
|
||||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is bar
|
/// This is bar
|
||||||
mint(r: Redeemer, ctx: ScriptContext) -> Bool {
|
mint(r: Redeemer, ctx: ScriptContext) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ description: "Code:\n\nvalidator thing ( ) {\n// What is the purpose of life\n\n
|
||||||
validator thing {
|
validator thing {
|
||||||
// What is the purpose of life
|
// What is the purpose of life
|
||||||
|
|
||||||
spend(d: Datum, r: Redeemer, ctx: ScriptContext) -> Bool {
|
spend(d: Datum, r: Redeemer, ctx: ScriptContext) {
|
||||||
True
|
True
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,9 @@ validator foo {
|
||||||
Void
|
Void
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
// I am lost
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I am lost
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ validator foo(Foo { a, b, .. }) {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ validator foo([Bar]: List<Bar>) {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ validator foo((Baz, Baz) as x) {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ validator fiz((fst, snd) as x: Pair<Int, Int>) {
|
||||||
todo
|
todo
|
||||||
}
|
}
|
||||||
|
|
||||||
else(_ctx) {
|
else(_) {
|
||||||
fail
|
fail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue