mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-18 23:02:35 +03:00
fix #1821
This commit is contained in:
parent
eee58883a6
commit
ba4f1666d1
@ -59,7 +59,6 @@ impl<'a> TypeChecker<'a> {
|
||||
match type_ {
|
||||
IntegerType::I8 => {
|
||||
let int = if self.negate {
|
||||
self.negate = false;
|
||||
format!("-{str_content}")
|
||||
} else {
|
||||
str_content.clone()
|
||||
@ -72,7 +71,6 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
IntegerType::I16 => {
|
||||
let int = if self.negate {
|
||||
self.negate = false;
|
||||
format!("-{str_content}")
|
||||
} else {
|
||||
str_content.clone()
|
||||
@ -85,7 +83,6 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
IntegerType::I32 => {
|
||||
let int = if self.negate {
|
||||
self.negate = false;
|
||||
format!("-{str_content}")
|
||||
} else {
|
||||
str_content.clone()
|
||||
@ -98,7 +95,6 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
IntegerType::I64 => {
|
||||
let int = if self.negate {
|
||||
self.negate = false;
|
||||
format!("-{str_content}")
|
||||
} else {
|
||||
str_content.clone()
|
||||
@ -111,7 +107,6 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
IntegerType::I128 => {
|
||||
let int = if self.negate {
|
||||
self.negate = false;
|
||||
format!("-{str_content}")
|
||||
} else {
|
||||
str_content.clone()
|
||||
@ -122,7 +117,6 @@ impl<'a> TypeChecker<'a> {
|
||||
.emit_err(TypeCheckerError::invalid_int_value(int, "i128", value.span()).into());
|
||||
}
|
||||
}
|
||||
|
||||
IntegerType::U8 if str_content.parse::<u8>().is_err() => self
|
||||
.handler
|
||||
.emit_err(TypeCheckerError::invalid_int_value(str_content, "u8", value.span()).into()),
|
||||
@ -256,7 +250,11 @@ impl<'a> TypeChecker<'a> {
|
||||
self.compare_expr_type(&unary.inner, expected, unary.inner.span())
|
||||
}
|
||||
UnaryOperation::Negate => {
|
||||
match expected.as_ref() {
|
||||
let prior_negate_state = self.negate;
|
||||
self.negate = true;
|
||||
let type_ = self.compare_expr_type(&unary.inner, expected, unary.inner.span());
|
||||
self.negate = prior_negate_state;
|
||||
match type_.as_ref() {
|
||||
Some(
|
||||
Type::IntegerType(
|
||||
IntegerType::I8
|
||||
@ -267,13 +265,13 @@ impl<'a> TypeChecker<'a> {
|
||||
)
|
||||
| Type::Field
|
||||
| Type::Group,
|
||||
) => self.negate = !self.negate,
|
||||
) => {},
|
||||
Some(t) => self
|
||||
.handler
|
||||
.emit_err(TypeCheckerError::type_is_not_negatable(t, unary.inner.span()).into()),
|
||||
_ => {}
|
||||
};
|
||||
self.compare_expr_type(&unary.inner, expected, unary.inner.span())
|
||||
type_
|
||||
}
|
||||
},
|
||||
Expression::Ternary(ternary) => {
|
||||
|
16
tests/compiler/statements/compare_fail.leo
Normal file
16
tests/compiler/statements/compare_fail.leo
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: inputs/u8.in
|
||||
*/
|
||||
|
||||
function main(a: u8) -> bool {
|
||||
let b: bool = -a == -1u8;
|
||||
let c: bool = -a > -1u8;
|
||||
let d: bool = -a < -1u8;
|
||||
let e: bool = -a >= -1u8;
|
||||
let f: bool = -a <= -1u8;
|
||||
let g: u8 = -a * -1u8;
|
||||
let h: u8 = -a ** -1u8;
|
||||
return b;
|
||||
}
|
5
tests/compiler/statements/inputs/u8.in
Normal file
5
tests/compiler/statements/inputs/u8.in
Normal file
@ -0,0 +1,5 @@
|
||||
[main]
|
||||
a: u8 = 1u8;
|
||||
|
||||
[registers]
|
||||
r0: bool = true;
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:4:20\n |\n 4 | let b: bool = -a == -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:4:26\n |\n 4 | let b: bool = -a == -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:5:20\n |\n 5 | let c: bool = -a > -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:5:25\n |\n 5 | let c: bool = -a > -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:6:20\n |\n 6 | let d: bool = -a < -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:6:25\n |\n 6 | let d: bool = -a < -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:7:20\n |\n 7 | let e: bool = -a >= -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:7:26\n |\n 7 | let e: bool = -a >= -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:8:20\n |\n 8 | let f: bool = -a <= -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:8:26\n |\n 8 | let f: bool = -a <= -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:9:18\n |\n 9 | let g: u8 = -a * -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:9:23\n |\n 9 | let g: u8 = -a * -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:10:18\n |\n 10 | let h: u8 = -a ** -1u8;\n | ^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:10:24\n |\n 10 | let h: u8 = -a ** -1u8;\n | ^^^\nError [ETYC0372005]: The type `u8` is not negatable\n --> compiler-test:10:24\n |\n 10 | let h: u8 = -a ** -1u8;\n | ^^^"
|
Loading…
Reference in New Issue
Block a user