mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 11:12:48 +03:00
Merge pull request #1267 from AleoHQ/bug/implicit-ternary-type-inference
[Bugfix] Ternary Implicit and Explicit Unkown Type
This commit is contained in:
commit
84e972c9ad
@ -87,7 +87,15 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> {
|
|||||||
)?);
|
)?);
|
||||||
let left: PartialType = if_true.get().get_type().unwrap().into();
|
let left: PartialType = if_true.get().get_type().unwrap().into();
|
||||||
|
|
||||||
let if_false = Cell::new(<&Expression<'a>>::from_ast(scope, &*value.if_false, expected_type)?);
|
let if_false = if expected_type.is_none() {
|
||||||
|
Cell::new(<&Expression<'a>>::from_ast(
|
||||||
|
scope,
|
||||||
|
&*value.if_false,
|
||||||
|
Some(left.clone()),
|
||||||
|
)?)
|
||||||
|
} else {
|
||||||
|
Cell::new(<&Expression<'a>>::from_ast(scope, &*value.if_false, expected_type)?)
|
||||||
|
};
|
||||||
let right = if_false.get().get_type().unwrap().into();
|
let right = if_false.get().get_type().unwrap().into();
|
||||||
|
|
||||||
if left != right {
|
if left != right {
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
[main]
|
||||||
|
x: u8 = 3;
|
||||||
|
y: bool = true;
|
||||||
|
|
||||||
|
[registers]
|
||||||
|
a: u8 = 0;
|
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
input_file: inputs/ternary_explicit_and_implicit.in
|
||||||
|
*/
|
||||||
|
|
||||||
|
function main(x: u8, y: bool) -> u8 {
|
||||||
|
return y ? x : 2;
|
||||||
|
}
|
@ -2,4 +2,4 @@
|
|||||||
namespace: Compile
|
namespace: Compile
|
||||||
expectation: Fail
|
expectation: Fail
|
||||||
outputs:
|
outputs:
|
||||||
- "Error [EASG0373021]: ternary sides had different types: left u32, right bool\n --> compiler-test:4:13\n |\n 4 | let x = true ? x: true;\n | ^^^^^^^^^^^^^^"
|
- "Error [EASG0373026]: unexpected type, expected: 'u32', received: 'bool'\n --> compiler-test:4:23\n |\n 4 | let x = true ? x: true;\n | ^^^^"
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
outputs:
|
||||||
|
- circuit:
|
||||||
|
num_public_variables: 0
|
||||||
|
num_private_variables: 25
|
||||||
|
num_constraints: 33
|
||||||
|
at: 00318b0f80b01b9e2d5a8154a536deb1545f04abd493a84071ef13dce1a9d92d
|
||||||
|
bt: 799ee4dc07f6320b8c3dcbd5ebdf6de8a4cf5af8b1edc45dbe5621c8a34fa38d
|
||||||
|
ct: 7b6ec9eacd65cfa47dfe7e73eb7c8fa4be804a9fb878fddf59fe5d06e7c04489
|
||||||
|
output:
|
||||||
|
- input_file: inputs/ternary_explicit_and_implicit.in
|
||||||
|
output:
|
||||||
|
registers:
|
||||||
|
a:
|
||||||
|
type: u8
|
||||||
|
value: "3"
|
||||||
|
initial_ast: 29b5d6188c9fe56eaee3024a900b92e4bd9445364551b85e924fe9a392bac35d
|
||||||
|
canonicalized_ast: 29b5d6188c9fe56eaee3024a900b92e4bd9445364551b85e924fe9a392bac35d
|
||||||
|
type_inferenced_ast: 02edde30e615a1ac3e87818daa6fca7e4d7c0c0c0a1a9d9159a0a4190c11ec8a
|
Loading…
Reference in New Issue
Block a user