From c345dbb3092716dd9bae022dbb7773e80a2cd68d Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:10:54 -0700 Subject: [PATCH 1/9] Add support for underscores in literals --- compiler/parser/src/parser/context.rs | 5 + compiler/parser/src/parser/expression.rs | 1 + compiler/parser/src/tokenizer/lexer.rs | 17 +- .../parser/expression/literal/underscore.out | 922 ++++++++++++++++++ .../expression/literal/underscore_fail.out | 21 + .../parser/statement/definition_fail.out | 2 + .../parser/unreachable/eat_int.out | 105 +- .../parser/expression/literal/underscore.leo | 125 +++ .../expression/literal/underscore_fail.leo | 22 + .../parser/statement/definition_fail.leo | 4 + tests/tests/parser/unreachable/eat_int.leo | 6 +- 11 files changed, 1175 insertions(+), 55 deletions(-) create mode 100644 tests/expectations/parser/expression/literal/underscore.out create mode 100644 tests/expectations/parser/expression/literal/underscore_fail.out create mode 100644 tests/tests/parser/expression/literal/underscore.leo create mode 100644 tests/tests/parser/expression/literal/underscore_fail.leo diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index e24ddabe6f..75b49e94e1 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -160,6 +160,11 @@ impl<'a> ParserContext<'a> { if let Token::Integer(value) = &self.token.token { let value = value.clone(); self.bump(); + // Reject value if the length is over 2 and the first character is 0 + if value.len() > 1 && value.starts_with('0') { + return Err(ParserError::unexpected(&self.token.token, "integer literal", self.token.span).into()); + } + Ok((PositiveNumber { value }, self.prev_token.span)) } else { Err(ParserError::unexpected(&self.token.token, "integer literal", self.token.span).into()) diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index 0e1142273d..5953c3d17a 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -429,6 +429,7 @@ impl ParserContext<'_> { if self.check_int() { // Eat a tuple member access. let (index, span) = self.eat_integer()?; + println!("index: {}", index); expr = Expression::Access(AccessExpression::Tuple(TupleAccess { tuple: Box::new(expr), index, diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index f7e3510b6b..e38eae517b 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -162,6 +162,7 @@ impl Token { } let mut int = String::new(); + let mut underscore_count = 0; while let Some(c) = input.next_if(|c| c.is_ascii_digit()) { if c == '0' && matches!(input.peek(), Some('x')) { int.push(c); @@ -170,9 +171,22 @@ impl Token { } int.push(c); + + // Allow unlimited underscores in between digits. + while matches!(input.peek(), Some('_')) { + underscore_count += 1; + input.next(); + } } - Ok((int.len(), Token::Integer(int))) + let length = int.len() + underscore_count; + + if underscore_count > 0 { + // Add leading zero to int. This will signal to the parser that the preprocessed int contained an underscore. + int.insert(0, '0'); + } + + Ok((length, Token::Integer(int))) } /// Returns a tuple: [(token length, token)] if the next token can be eaten, otherwise returns an error. @@ -264,6 +278,7 @@ impl Token { // + 2 to account for parsing quotation marks. return Ok((string.len() + 2, Token::StaticString(string))); } + x if x.is_ascii_digit() => return Self::eat_integer(&mut input), '!' => return match_two(&mut input, Token::Not, '=', Token::NotEq), '?' => return match_one(&mut input, Token::Question), diff --git a/tests/expectations/parser/expression/literal/underscore.out b/tests/expectations/parser/expression/literal/underscore.out new file mode 100644 index 0000000000..1d3a09b500 --- /dev/null +++ b/tests/expectations/parser/expression/literal/underscore.out @@ -0,0 +1,922 @@ +--- +namespace: ParseExpression +expectation: Pass +outputs: + - "" + - Literal: + Integer: + - I8 + - "11" + - span: + lo: 0 + hi: 10194 + - 0 + - Literal: + Integer: + - I8 + - "12" + - span: + lo: 0 + hi: 4 + - 0 + - Literal: + Integer: + - I8 + - "12" + - span: + lo: 0 + hi: 5 + - 0 + - Literal: + Integer: + - I8 + - "123" + - span: + lo: 0 + hi: 6 + - 0 + - Literal: + Integer: + - I8 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - I8 + - "12345" + - span: + lo: 0 + hi: 10 + - 0 + - "" + - Literal: + Integer: + - I16 + - "1234" + - span: + lo: 0 + hi: 7 + - 0 + - Literal: + Integer: + - I16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - I16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - I16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - I16 + - "1234" + - span: + lo: 0 + hi: 9 + - 0 + - "" + - Literal: + Integer: + - I32 + - "123" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - I32 + - "123" + - span: + lo: 0 + hi: 10 + - 0 + - Literal: + Integer: + - I32 + - "000000" + - span: + lo: 0 + hi: 13 + - 0 + - Literal: + Integer: + - I32 + - "02930932" + - span: + lo: 0 + hi: 30 + - 0 + - Literal: + Integer: + - I32 + - "00" + - span: + lo: 0 + hi: 6 + - 0 + - Literal: + Integer: + - I32 + - "000001034043240" + - span: + lo: 0 + hi: 92 + - 0 + - "" + - Literal: + Integer: + - I64 + - "1234567890123456" + - span: + lo: 0 + hi: 19 + - 0 + - Literal: + Integer: + - I64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - I64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - I64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - I64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - "" + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 36 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - "" + - Literal: + Integer: + - U8 + - "12" + - span: + lo: 0 + hi: 4 + - 0 + - Literal: + Integer: + - U8 + - "12" + - span: + lo: 0 + hi: 5 + - 0 + - Literal: + Integer: + - U8 + - "123" + - span: + lo: 0 + hi: 6 + - 0 + - Literal: + Integer: + - U8 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - U8 + - "12345" + - span: + lo: 0 + hi: 10 + - 0 + - "" + - Literal: + Integer: + - U16 + - "1234" + - span: + lo: 0 + hi: 7 + - 0 + - Literal: + Integer: + - U16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - U16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - U16 + - "1234" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Integer: + - U16 + - "1234" + - span: + lo: 0 + hi: 9 + - 0 + - "" + - Literal: + Integer: + - U32 + - "12345678" + - span: + lo: 0 + hi: 11 + - 0 + - Literal: + Integer: + - U32 + - "12345678" + - span: + lo: 0 + hi: 12 + - 0 + - Literal: + Integer: + - U32 + - "12345678" + - span: + lo: 0 + hi: 12 + - 0 + - Literal: + Integer: + - U32 + - "12345678" + - span: + lo: 0 + hi: 12 + - 0 + - Literal: + Integer: + - U32 + - "12345678" + - span: + lo: 0 + hi: 12 + - 0 + - "" + - Literal: + Integer: + - U64 + - "1234567890123456" + - span: + lo: 0 + hi: 19 + - 0 + - Literal: + Integer: + - U64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - U64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - U64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - Literal: + Integer: + - U64 + - "1234567890123456" + - span: + lo: 0 + hi: 20 + - 0 + - "" + - Literal: + Integer: + - U128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 36 + - 0 + - Literal: + Integer: + - U128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - Literal: + Integer: + - I128 + - "12345678901234567890123456789012" + - span: + lo: 0 + hi: 37 + - 0 + - "" + - Literal: + Field: + - "456" + - span: + lo: 0 + hi: 8 + - 0 + - Literal: + Field: + - "87377802873778028737780287377802873778028737780287377802873778028737780287377802" + - span: + lo: 0 + hi: 88 + - 0 + - Literal: + Field: + - "8737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802" + - span: + lo: 0 + hi: 428 + - 0 + - Literal: + Field: + - "340130024" + - span: + lo: 0 + hi: 18 + - 0 + - Literal: + Field: + - "158951116" + - span: + lo: 0 + hi: 19 + - 0 + - "" + - Literal: + Scalar: + - "724940549" + - span: + lo: 0 + hi: 18 + - 0 + - Literal: + Scalar: + - "487101620" + - span: + lo: 0 + hi: 18 + - 0 + - Literal: + Scalar: + - "100234" + - span: + lo: 0 + hi: 14 + - 0 + - Literal: + Scalar: + - "1234" + - span: + lo: 0 + hi: 11 + - 0 + - Literal: + Scalar: + - "1234" + - span: + lo: 0 + hi: 11 + - 0 + - Literal: + Scalar: + - "1234" + - span: + lo: 0 + hi: 11 + - 0 + - Literal: + Scalar: + - "1234" + - span: + lo: 0 + hi: 12 + - 0 + - "" + - Literal: + Group: + Single: + - "199375617" + - span: + lo: 0 + hi: 23 + - 0 + - Literal: + Group: + Single: + - "680337189" + - span: + lo: 0 + hi: 32 + - 0 + - Literal: + Group: + Single: + - "81879931" + - span: + lo: 0 + hi: 17 + - 0 + - Literal: + Group: + Single: + - "893693281" + - span: + lo: 0 + hi: 18 + - 0 + - Literal: + Group: + Single: + - "87377802" + - span: + lo: 0 + hi: 19 + - 0 + - Literal: + Group: + Single: + - "84699261" + - span: + lo: 0 + hi: 15 + - 0 + - Literal: + Group: + Single: + - "292826090" + - span: + lo: 0 + hi: 18 + - 0 + - "" + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 9 + y: + Number: + - "-456" + - span: + lo: 11 + hi: 17 + span: + lo: 0 + hi: 23 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "-123" + - span: + lo: 2 + hi: 8 + y: + Number: + - "456" + - span: + lo: 9 + hi: 14 + span: + lo: 0 + hi: 20 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "-123" + - span: + lo: 2 + hi: 7 + y: + Number: + - "456" + - span: + lo: 8 + hi: 17 + span: + lo: 0 + hi: 23 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 6 + y: Inferred + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 6 + y: SignLow + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "0123" + - span: + lo: 1 + hi: 10 + y: SignLow + span: + lo: 0 + hi: 19 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 5 + y: SignHigh + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "0123" + - span: + lo: 1 + hi: 9 + y: SignHigh + span: + lo: 0 + hi: 18 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 5 + y: SignLow + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 6 + y: Inferred + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: SignHigh + y: + Number: + - "345" + - span: + lo: 4 + hi: 9 + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: Inferred + y: + Number: + - "345" + - span: + lo: 4 + hi: 8 + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: SignHigh + y: + Number: + - "345" + - span: + lo: 4 + hi: 8 + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: SignLow + y: + Number: + - "345" + - span: + lo: 4 + hi: 12 + span: + lo: 0 + hi: 18 + id: 0 + - Literal: + Group: + Tuple: + x: SignHigh + y: + Number: + - "345" + - span: + lo: 4 + hi: 8 + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: SignLow + y: + Number: + - "35" + - span: + lo: 4 + hi: 7 + span: + lo: 0 + hi: 13 + id: 0 + - Literal: + Group: + Tuple: + x: Inferred + y: + Number: + - "3452" + - span: + lo: 4 + hi: 9 + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "12" + - span: + lo: 1 + hi: 4 + y: + Number: + - "34" + - span: + lo: 5 + hi: 8 + span: + lo: 0 + hi: 14 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 5 + y: + Number: + - "45" + - span: + lo: 6 + hi: 9 + span: + lo: 0 + hi: 15 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 5 + y: + Number: + - "456" + - span: + lo: 6 + hi: 10 + span: + lo: 0 + hi: 16 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "123" + - span: + lo: 1 + hi: 6 + y: + Number: + - "456" + - span: + lo: 7 + hi: 12 + span: + lo: 0 + hi: 18 + id: 0 + - Literal: + Group: + Tuple: + x: + Number: + - "1234" + - span: + lo: 1 + hi: 7 + y: + Number: + - "567" + - span: + lo: 8 + hi: 12 + span: + lo: 0 + hi: 18 + id: 0 diff --git a/tests/expectations/parser/expression/literal/underscore_fail.out b/tests/expectations/parser/expression/literal/underscore_fail.out new file mode 100644 index 0000000000..f5532fc87e --- /dev/null +++ b/tests/expectations/parser/expression/literal/underscore_fail.out @@ -0,0 +1,21 @@ +--- +namespace: ParseExpression +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | ______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________1i8\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | ___1_2i8\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _________________i32\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _123456i64\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _9012i128\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _3_4_5u8\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _4u16\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _5678u32\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _123456u64\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _345678901234567890123456789012i128\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | __737780287377___________80287377802873778028737780287377802873778028737______78028737780287377802873778028737780287____37780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802field\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | ___4940549scalar\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | __9__3756___17group\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:2\n |\n 1 | (_1___2__3,-4_5__6)group\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:3\n |\n 1 | (-__12___3,456__)group\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:3\n |\n 1 | (-_12__3,_45______6)group\n | ^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:1\n |\n 1 | _023group\n | ^" diff --git a/tests/expectations/parser/statement/definition_fail.out b/tests/expectations/parser/statement/definition_fail.out index 355c35f790..7ae81b45a0 100644 --- a/tests/expectations/parser/statement/definition_fail.out +++ b/tests/expectations/parser/statement/definition_fail.out @@ -45,3 +45,5 @@ outputs: - "Error [EPAR0370016]: Could not lex the following content: `🦀:`.\n" - "Error [EPAR0370005]: expected : -- found '='\n --> test:1:9\n |\n 1 | let (x) = ...;\n | ^" - "Error [EPAR0370029]: A tuple expression must have at least two elements.\n --> test:1:5\n |\n 1 | let (x,) = ...;\n | ^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:5\n |\n 1 | let _1: u8 = 1u8;\n | ^" + - "Error [EPAR0370017]: Could not parse the implicit value: 1091.\n --> test:1:5\n |\n 1 | let 1___091: u8 = 12u8;\n | ^^^^^^^" diff --git a/tests/expectations/parser/unreachable/eat_int.out b/tests/expectations/parser/unreachable/eat_int.out index 600a89e081..8a9b63f643 100644 --- a/tests/expectations/parser/unreachable/eat_int.out +++ b/tests/expectations/parser/unreachable/eat_int.out @@ -2,55 +2,56 @@ namespace: ParseStatement expectation: Fail outputs: - - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '-'\n --> test:1:3\n |\n 1 | x.-12\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_;\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_.\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_import\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_,\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_*\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_+\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_-\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_/\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_[\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_]\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_{\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_}\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_(\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_)\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_:\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_::\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_?\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0__\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_=\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_==\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_!\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_!=\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_>=\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_<\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_<=\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_..\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_as\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_console\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_const\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_let\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_for\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_if\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_else\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_i8\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_i16\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_i32\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_i64\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_i128\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_u8\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_u16\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_u32\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_u64\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_u128\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_&\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_return\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_self\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_Self\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_true\n | ^" - - "Error [EPAR0370005]: expected ; -- found '_'\n --> test:1:4\n |\n 1 | x.0_false\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:5\n |\n 1 | x.0_;\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:6\n |\n 1 | x.0_0;\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:5\n |\n 1 | x.01;\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '.'\n --> test:1:5\n |\n 1 | x.0_.\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found 'import'\n --> test:1:5\n |\n 1 | x.0_import\n | ^^^^^^" + - "Error [EPAR0370005]: expected integer literal -- found ','\n --> test:1:5\n |\n 1 | x.0_,\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '*'\n --> test:1:5\n |\n 1 | x.0_*\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '+'\n --> test:1:5\n |\n 1 | x.0_+\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '-'\n --> test:1:5\n |\n 1 | x.0_-\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '/'\n --> test:1:5\n |\n 1 | x.0_/\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '['\n --> test:1:5\n |\n 1 | x.0_[\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ']'\n --> test:1:5\n |\n 1 | x.0_]\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '{'\n --> test:1:5\n |\n 1 | x.0_{\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '}'\n --> test:1:5\n |\n 1 | x.0_}\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '('\n --> test:1:5\n |\n 1 | x.0_(\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ')'\n --> test:1:5\n |\n 1 | x.0_)\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ':'\n --> test:1:5\n |\n 1 | x.0_:\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '::'\n --> test:1:5\n |\n 1 | x.0_::\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found '?'\n --> test:1:5\n |\n 1 | x.0_?\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found ''\n --> test:1:3\n |\n 1 | x.0__\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found '='\n --> test:1:5\n |\n 1 | x.0_=\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '=='\n --> test:1:5\n |\n 1 | x.0_==\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found '!'\n --> test:1:5\n |\n 1 | x.0_!\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '!='\n --> test:1:5\n |\n 1 | x.0_!=\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '>='\n --> test:1:5\n |\n 1 | x.0_>=\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found '<'\n --> test:1:5\n |\n 1 | x.0_<\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '<='\n --> test:1:5\n |\n 1 | x.0_<=\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found '..'\n --> test:1:5\n |\n 1 | x.0_..\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found 'as'\n --> test:1:5\n |\n 1 | x.0_as\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found 'console'\n --> test:1:5\n |\n 1 | x.0_console\n | ^^^^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'const'\n --> test:1:5\n |\n 1 | x.0_const\n | ^^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'let'\n --> test:1:5\n |\n 1 | x.0_let\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'for'\n --> test:1:5\n |\n 1 | x.0_for\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'if'\n --> test:1:5\n |\n 1 | x.0_if\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found 'else'\n --> test:1:5\n |\n 1 | x.0_else\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'i8'\n --> test:1:5\n |\n 1 | x.0_i8\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found 'i16'\n --> test:1:5\n |\n 1 | x.0_i16\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'i32'\n --> test:1:5\n |\n 1 | x.0_i32\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'i64'\n --> test:1:5\n |\n 1 | x.0_i64\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'i128'\n --> test:1:5\n |\n 1 | x.0_i128\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'u8'\n --> test:1:5\n |\n 1 | x.0_u8\n | ^^" + - "Error [EPAR0370005]: expected integer literal -- found 'u16'\n --> test:1:5\n |\n 1 | x.0_u16\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'u32'\n --> test:1:5\n |\n 1 | x.0_u32\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'u64'\n --> test:1:5\n |\n 1 | x.0_u64\n | ^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'u128'\n --> test:1:5\n |\n 1 | x.0_u128\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found '&'\n --> test:1:5\n |\n 1 | x.0_&\n | ^" + - "Error [EPAR0370005]: expected integer literal -- found 'return'\n --> test:1:5\n |\n 1 | x.0_return\n | ^^^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'self'\n --> test:1:5\n |\n 1 | x.0_self\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'Self'\n --> test:1:5\n |\n 1 | x.0_Self\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'true'\n --> test:1:5\n |\n 1 | x.0_true\n | ^^^^" + - "Error [EPAR0370005]: expected integer literal -- found 'false'\n --> test:1:5\n |\n 1 | x.0_false\n | ^^^^^" diff --git a/tests/tests/parser/expression/literal/underscore.leo b/tests/tests/parser/expression/literal/underscore.leo new file mode 100644 index 0000000000..d17688db19 --- /dev/null +++ b/tests/tests/parser/expression/literal/underscore.leo @@ -0,0 +1,125 @@ +/* +namespace: ParseExpression +expectation: Pass +*/ + +// i8 +1______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________1i8 +12i8 +1_2i8 +12_3i8 +12_3_4i8 +12_3_4_5i8 + +// i16 +1234i16 +1_234i16 +12_34i16 +123_4i16 +12_3_4i16 + +// i32 +1_2_3i32 +1__2__3i32 +0__0__0000i32 +0_2930_932_________________i32 +0_0i32 +000001034043240__________________________________________________________________________i32 + +// i64 +1234567890123456i64 +1_234567890123456i64 +12_34567890123456i64 +123456789012_3456i64 +1234567890_123456i64 + +// i128 +12345678901234567890123456789012i128 +1_2345678901234567890123456789012i128 +12_345678901234567890123456789012i128 +1234567890123456789012345678_9012i128 +12345678901234567890_123456789012i128 + +// u8 +12u8 +1_2u8 +12_3u8 +12_3_4u8 +12_3_4_5u8 + +// u16 +1234u16 +1_234u16 +12_34u16 +123_4u16 +12_3_4u16 + +// u32 +12345678u32 +1_2345678u32 +12_345678u32 +1234567_8u32 +1234_5678u32 + +// u64 +1234567890123456u64 +1_234567890123456u64 +12_34567890123456u64 +123456789012_3456u64 +1234567890_123456u64 + +// u128 +12345678901234567890123456789012u128 +1_2345678901234567890123456789012u128 +12_345678901234567890123456789012i128 +1234567890123456789012345678_9012i128 +12345678901234567890_123456789012i128 + +// field +456field +8737780287___3778028737780287377802873778028737780287377802873778028737780287377802field +8__737780287377___________80287377802873778028737780287377802873778028737______78028737780287377802873778028737780287____37780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802field +340130____024field +15_8951116____field + +// scalar +72___4940549scalar +48710162___0scalar +100__234scalar +1_234scalar +12_34scalar +123_4scalar +12_3_4scalar + +// mono group +19____9__3756___17group +68______03______3718____9__group +818__79931__group +8__9369328__1group +873__778____02group +84699__261group +29__282609__0group + +// group +(1___2__3,-4_5__6)group +(-12___3,456__)group +(-12__3,45______6)group +(1__23, _)group +(12__3, -)group +(0___1_2_3, -)group +(12_3, +)group +(0____123, +)group +(12_3, -)group +(12__3, _)group +(+, 345__)group +(_, 34_5)group +(+, 345_)group +(-, 34_____5)group +(+, 3_45)group +(-, 3_5)group +(_, 345_2)group +(1_2,3_4)group +(12_3,4_5)group +(12_3,45_6)group +(1_2_3,4_5_6)group +(12_3_4,56_7)group \ No newline at end of file diff --git a/tests/tests/parser/expression/literal/underscore_fail.leo b/tests/tests/parser/expression/literal/underscore_fail.leo new file mode 100644 index 0000000000..9472cdb5f1 --- /dev/null +++ b/tests/tests/parser/expression/literal/underscore_fail.leo @@ -0,0 +1,22 @@ +/* +namespace: ParseExpression +expectation: Fail +*/ + +______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________1i8 +___1_2i8 +_________________i32 +_123456i64 +_9012i128 +_3_4_5u8 +_4u16 +_5678u32 +_123456u64 +_345678901234567890123456789012i128 +__737780287377___________80287377802873778028737780287377802873778028737______78028737780287377802873778028737780287____37780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802field +___4940549scalar +__9__3756___17group +(_1___2__3,-4_5__6)group +(-__12___3,456__)group +(-_12__3,_45______6)group +_023group \ No newline at end of file diff --git a/tests/tests/parser/statement/definition_fail.leo b/tests/tests/parser/statement/definition_fail.leo index 0f096e89a0..6e570d397e 100644 --- a/tests/tests/parser/statement/definition_fail.leo +++ b/tests/tests/parser/statement/definition_fail.leo @@ -93,3 +93,7 @@ let 🦀: u8 = 0; let (x) = ...; let (x,) = ...; + +let _1: u8 = 1u8; + +let 1___091: u8 = 12u8; \ No newline at end of file diff --git a/tests/tests/parser/unreachable/eat_int.leo b/tests/tests/parser/unreachable/eat_int.leo index 20029228f8..64bf596c69 100644 --- a/tests/tests/parser/unreachable/eat_int.leo +++ b/tests/tests/parser/unreachable/eat_int.leo @@ -3,10 +3,12 @@ namespace: ParseStatement expectation: Fail */ -x.-12 - x.0_; +x.0_0; + +x.01; + x.0_. x.0_import From 7e6b1d9ddbeb60d6e1751ada32281adda91c7cff Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:29:35 -0700 Subject: [PATCH 2/9] remove println --- compiler/parser/src/parser/expression.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index 5953c3d17a..0e1142273d 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -429,7 +429,6 @@ impl ParserContext<'_> { if self.check_int() { // Eat a tuple member access. let (index, span) = self.eat_integer()?; - println!("index: {}", index); expr = Expression::Access(AccessExpression::Tuple(TupleAccess { tuple: Box::new(expr), index, From 439d2b29dec96e0b5483edf02627416a1ab27059 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:07:00 -0700 Subject: [PATCH 3/9] loop unrolling compatible with underscores --- compiler/ast/src/value/mod.rs | 27 +-- compiler/parser/src/parser/context.rs | 6 +- compiler/parser/src/parser/expression.rs | 2 +- compiler/parser/src/tokenizer/lexer.rs | 20 +- .../src/type_checking/check_expressions.rs | 5 +- .../src/type_checking/check_statements.rs | 26 +++ errors/src/errors/parser/parser_errors.rs | 8 + .../errors/type_checker/type_checker_error.rs | 14 ++ .../expectations/compiler/integers/i8/add.out | 14 +- .../compiler/statements/block.out | 14 +- .../statements/loop_decreasing_fail.out | 5 + .../statements/underscore_for_loop.out | 12 ++ .../parser/expression/literal/underscore.out | 182 +++++++++--------- .../parser/statement/definition_fail.out | 2 +- .../parser/unreachable/eat_int.out | 106 +++++----- tests/tests/compiler/integers/i8/add.leo | 2 +- tests/tests/compiler/statements/block.leo | 8 +- .../statements/loop_decreasing_fail.leo | 16 ++ .../statements/underscore_for_loop.leo | 70 +++++++ 19 files changed, 341 insertions(+), 198 deletions(-) create mode 100644 tests/expectations/compiler/statements/loop_decreasing_fail.out create mode 100644 tests/expectations/compiler/statements/underscore_for_loop.out create mode 100644 tests/tests/compiler/statements/loop_decreasing_fail.leo create mode 100644 tests/tests/compiler/statements/underscore_for_loop.leo diff --git a/compiler/ast/src/value/mod.rs b/compiler/ast/src/value/mod.rs index 7f9db8ddb5..c30c03050d 100644 --- a/compiler/ast/src/value/mod.rs +++ b/compiler/ast/src/value/mod.rs @@ -877,18 +877,21 @@ impl TryFrom<&Literal> for Value { Literal::Group(group_literal) => Self::Group(group_literal.clone()), Literal::Scalar(string, span, _) => Self::Scalar(string.clone(), *span), Literal::String(string, span, _) => Self::String(string.clone(), *span), - Literal::Integer(integer_type, string, span, _) => match integer_type { - IntegerType::U8 => Self::U8(string.parse()?, *span), - IntegerType::U16 => Self::U16(string.parse()?, *span), - IntegerType::U32 => Self::U32(string.parse()?, *span), - IntegerType::U64 => Self::U64(string.parse()?, *span), - IntegerType::U128 => Self::U128(string.parse()?, *span), - IntegerType::I8 => Self::I8(string.parse()?, *span), - IntegerType::I16 => Self::I16(string.parse()?, *span), - IntegerType::I32 => Self::I32(string.parse()?, *span), - IntegerType::I64 => Self::I64(string.parse()?, *span), - IntegerType::I128 => Self::I128(string.parse()?, *span), - }, + Literal::Integer(integer_type, raw_string, span, _) => { + let string = raw_string.replace("_", ""); + match integer_type { + IntegerType::U8 => Self::U8(string.parse()?, *span), + IntegerType::U16 => Self::U16(string.parse()?, *span), + IntegerType::U32 => Self::U32(string.parse()?, *span), + IntegerType::U64 => Self::U64(string.parse()?, *span), + IntegerType::U128 => Self::U128(string.parse()?, *span), + IntegerType::I8 => Self::I8(string.parse()?, *span), + IntegerType::I16 => Self::I16(string.parse()?, *span), + IntegerType::I32 => Self::I32(string.parse()?, *span), + IntegerType::I64 => Self::I64(string.parse()?, *span), + IntegerType::I128 => Self::I128(string.parse()?, *span), + } + } }) } } diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index 75b49e94e1..553a87b11b 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -156,13 +156,13 @@ impl<'a> ParserContext<'a> { /// Removes the next token if it is a [`Token::Integer(_)`] and returns it, or [None] if /// the next token is not a [`Token::Integer(_)`] or if the next token does not exist. /// - pub fn eat_integer(&mut self) -> Result<(PositiveNumber, Span)> { + pub fn eat_whole_number(&mut self) -> Result<(PositiveNumber, Span)> { if let Token::Integer(value) = &self.token.token { let value = value.clone(); self.bump(); // Reject value if the length is over 2 and the first character is 0 - if value.len() > 1 && value.starts_with('0') { - return Err(ParserError::unexpected(&self.token.token, "integer literal", self.token.span).into()); + if (value.len() > 1 && value.starts_with('0')) || value.contains('_') { + return Err(ParserError::tuple_index_must_be_whole_number(&self.token.token, "whole number", self.token.span).into()); } Ok((PositiveNumber { value }, self.prev_token.span)) diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index 0e1142273d..09f913112e 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -428,7 +428,7 @@ impl ParserContext<'_> { if self.eat(&Token::Dot) { if self.check_int() { // Eat a tuple member access. - let (index, span) = self.eat_integer()?; + let (index, span) = self.eat_whole_number()?; expr = Expression::Access(AccessExpression::Tuple(TupleAccess { tuple: Box::new(expr), index, diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index e38eae517b..5c814de8b7 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -162,8 +162,9 @@ impl Token { } let mut int = String::new(); - let mut underscore_count = 0; - while let Some(c) = input.next_if(|c| c.is_ascii_digit()) { + + // Note that it is still impossible to have a number that starts with an `_` because eat_integer is only called when the first character is a digit. + while let Some(c) = input.next_if(|c| c.is_ascii_digit() || *c == '_') { if c == '0' && matches!(input.peek(), Some('x')) { int.push(c); int.push(input.next().unwrap()); @@ -171,22 +172,9 @@ impl Token { } int.push(c); - - // Allow unlimited underscores in between digits. - while matches!(input.peek(), Some('_')) { - underscore_count += 1; - input.next(); - } - } - - let length = int.len() + underscore_count; - - if underscore_count > 0 { - // Add leading zero to int. This will signal to the parser that the preprocessed int contained an underscore. - int.insert(0, '0'); } - Ok((length, Token::Integer(int))) + Ok((int.len(), Token::Integer(int))) } /// Returns a tuple: [(token length, token)] if the next token can be eaten, otherwise returns an error. diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 6f4c516d00..536ba4b538 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -588,7 +588,8 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { } fn visit_literal(&mut self, input: &'a Literal, expected: &Self::AdditionalInput) -> Self::Output { - fn parse_integer_literal(handler: &Handler, string: &String, span: Span, type_string: &str) { + fn parse_integer_literal(handler: &Handler, raw_string: &String, span: Span, type_string: &str) { + let string = raw_string.replace("_", ""); if string.parse::().is_err() { handler.emit_err(TypeCheckerError::invalid_int_value(string, type_string, span)); } @@ -620,7 +621,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { self.assert_and_return_type(Type::Integer(IntegerType::U128), expected, input.span()) } IntegerType::I8 => { - parse_integer_literal::(self.handler, string, input.span(), "i8"); + parse_integer_literal::(self.handler, &string, input.span(), "i8"); self.assert_and_return_type(Type::Integer(IntegerType::I8), expected, input.span()) } IntegerType::I16 => { diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index 577e52e876..c1fe8a757a 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -275,6 +275,9 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { if let Ok(value) = Value::try_from(literal) { input.start_value.replace(Some(value)); } + else { + self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span())); + } } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span())); } @@ -287,9 +290,32 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { if let Ok(value) = Value::try_from(literal) { input.stop_value.replace(Some(value)); } + else { + self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); + } } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); } + + if match (input.start_value.borrow().as_ref(), input.stop_value.borrow().as_ref()) { + (Some(Value::I8(lower_bound, _)), Some(Value::I8(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::I16(lower_bound, _)), Some(Value::I16(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::I32(lower_bound, _)), Some(Value::I32(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::I64(lower_bound, _)), Some(Value::I64(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::I128(lower_bound, _)), Some(Value::I128(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::U8(lower_bound, _)), Some(Value::U8(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::U16(lower_bound, _)), Some(Value::U16(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::U32(lower_bound, _)), Some(Value::U32(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::U64(lower_bound, _)), Some(Value::U64(upper_bound, _))) => lower_bound >= upper_bound, + (Some(Value::U128(lower_bound, _)), Some(Value::U128(upper_bound, _))) => lower_bound >= upper_bound, + _ => { + self.emit_err(TypeCheckerError::loop_bound_type_mismatch(input.stop.span())); + false + } + } { + self.emit_err(TypeCheckerError::loop_range_decreasing(input.stop.span())); + } + } fn visit_return(&mut self, input: &'a ReturnStatement) { diff --git a/errors/src/errors/parser/parser_errors.rs b/errors/src/errors/parser/parser_errors.rs index 92776bede9..75e5a7b281 100644 --- a/errors/src/errors/parser/parser_errors.rs +++ b/errors/src/errors/parser/parser_errors.rs @@ -283,4 +283,12 @@ create_messages!( msg: format!("`console` statements are not yet supported."), help: Some("Consider using `assert`, `assert_eq`, or `assert_neq` instead.".to_string()), } + + /// Enforce that tuple index must not have leading 0, or underscore in between digits + @formatted + tuple_index_must_be_whole_number { + args: (found: impl Display, expected: impl Display), + msg: format!("expected {expected} -- found '{found}'"), + help: None, + } ); diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 8aab4ad49b..100656ca59 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -642,4 +642,18 @@ create_messages!( msg: format!("This operation can only be used in a `finalize` block."), help: None, } + + @formatted + loop_range_decreasing { + args: (), + msg: format!("The loop range must be decreasing."), + help: None, + } + + @formatted + loop_bound_type_mismatch { + args: (), + msg: format!("The loop bounds must be same type"), + help: None, + } ); diff --git a/tests/expectations/compiler/integers/i8/add.out b/tests/expectations/compiler/integers/i8/add.out index 5ff1f415ab..5c17c988b9 100644 --- a/tests/expectations/compiler/integers/i8/add.out +++ b/tests/expectations/compiler/integers/i8/add.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 07d84ab17fb71320a01c243bc220b7273b27cd2f4c572b11852afd5128563bb7 - unrolled_ast: 07d84ab17fb71320a01c243bc220b7273b27cd2f4c572b11852afd5128563bb7 - ssa_ast: e089fb6b899d91adc9df149257039d771880ff6d31cbcc1c3fcf3223d61e4fcc - flattened_ast: a7a814b61f9d3d520375e192824edaf10f378cd65f30746bfcb1e81d4b524940 - inlined_ast: a7a814b61f9d3d520375e192824edaf10f378cd65f30746bfcb1e81d4b524940 - dce_ast: a7a814b61f9d3d520375e192824edaf10f378cd65f30746bfcb1e81d4b524940 - bytecode: 7e5db24495ea3dcca85545d83273ce3c02faae5a2bcaef3a9448920ac68daeda + - - initial_ast: 52c17634e4873e8aaed7bc62cbafc7b36a805930fedac25679ea1e44ad68b9d9 + unrolled_ast: 52c17634e4873e8aaed7bc62cbafc7b36a805930fedac25679ea1e44ad68b9d9 + ssa_ast: e1b4addbd3d414377d5cac95a487c1d9aca029ddc222dbab08ed00a3d80298d8 + flattened_ast: 4d5bcd013ddbfa4fe4397ca346b8cbfd74cb0c1f571ac3af4546493550164939 + inlined_ast: 4d5bcd013ddbfa4fe4397ca346b8cbfd74cb0c1f571ac3af4546493550164939 + dce_ast: 4d5bcd013ddbfa4fe4397ca346b8cbfd74cb0c1f571ac3af4546493550164939 + bytecode: b55a8d40426fb145352765c99ed1875c872f2a6a0aeaa46f5734c543b5cc17a0 warnings: "" diff --git a/tests/expectations/compiler/statements/block.out b/tests/expectations/compiler/statements/block.out index 5347ce8c52..42810ede58 100644 --- a/tests/expectations/compiler/statements/block.out +++ b/tests/expectations/compiler/statements/block.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 26ccd058cce0c3bd1c9812903f1cc21e8886905964ca565d41782e08631a4722 - unrolled_ast: 26ccd058cce0c3bd1c9812903f1cc21e8886905964ca565d41782e08631a4722 - ssa_ast: b99ef5259b4d8c13f7c716d548e5005b0f90291fa128cf5ff2c576a532bcf47d - flattened_ast: 29f8729f583503bf96da596bf6308c90a52837bfe47948b19bce1a75ee47efdb - inlined_ast: 29f8729f583503bf96da596bf6308c90a52837bfe47948b19bce1a75ee47efdb - dce_ast: 29f8729f583503bf96da596bf6308c90a52837bfe47948b19bce1a75ee47efdb - bytecode: 9f2bbabd0f858db6e5f4e529fdd5e246023994bf27bbabe6dc1aa6bbf8bf5cfd + - - initial_ast: 6fbf3a5297e1c0ac385d9a0bca37461e3f05db150256c4805c933b995291e8a8 + unrolled_ast: 0b30fd3c36c48eacdec271e2be37ed26d0a903a62175524283ac214aee38e861 + ssa_ast: a5246ba65141147bdf42b84a46efbd81e97ede4fddb70cf08e758ab0b4908ed0 + flattened_ast: da5289263185bf3629befaa4571978fc7a59d27f8af2da7e5c47181509f73eaf + inlined_ast: da5289263185bf3629befaa4571978fc7a59d27f8af2da7e5c47181509f73eaf + dce_ast: c05d81f5bbd7df8fa456f8dad5aff1d1ca169d9defbd84829698895f452826f2 + bytecode: 1a9f3c92be71c05ccb8a22286f99a0ba1e88d1f580dec2c7305ec17b08e0089a warnings: "" diff --git a/tests/expectations/compiler/statements/loop_decreasing_fail.out b/tests/expectations/compiler/statements/loop_decreasing_fail.out new file mode 100644 index 0000000000..f8a8ca8481 --- /dev/null +++ b/tests/expectations/compiler/statements/loop_decreasing_fail.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [ETYC0372078]: The loop range must be decreasing.\n --> compiler-test:7:28\n |\n 7 | for i: i8 in 10i8..5i8 {\n | ^^^\n" diff --git a/tests/expectations/compiler/statements/underscore_for_loop.out b/tests/expectations/compiler/statements/underscore_for_loop.out new file mode 100644 index 0000000000..76e3f5eb69 --- /dev/null +++ b/tests/expectations/compiler/statements/underscore_for_loop.out @@ -0,0 +1,12 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - - initial_ast: 0cbd0b999474cce80a0958de212e0cfac204c3b3e8e70efe017754a8085971d3 + unrolled_ast: 8462d3bb0f91c5ae618402dfb9ae88345b5b271e88febea430a6c8b174f30573 + ssa_ast: eb19911f0f9788d733db228c52493ec9f4be8a4616dd3b6268f254707190830d + flattened_ast: c36e658478aeed0e41f2001dacbd8e5c2d5d59a25d4c3b7d2827034fe9404080 + inlined_ast: c36e658478aeed0e41f2001dacbd8e5c2d5d59a25d4c3b7d2827034fe9404080 + dce_ast: 51157d270af2da9d52fc6d514ccfe2023d8c11e475949e41696c4527a6b909c8 + bytecode: 61cc464cdc1104635ea399648d62a06b112dc3462634b3f992151c6e5572d6f7 + warnings: "" diff --git a/tests/expectations/parser/expression/literal/underscore.out b/tests/expectations/parser/expression/literal/underscore.out index 1d3a09b500..f9c246c369 100644 --- a/tests/expectations/parser/expression/literal/underscore.out +++ b/tests/expectations/parser/expression/literal/underscore.out @@ -6,7 +6,7 @@ outputs: - Literal: Integer: - I8 - - "11" + - 1______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________1 - span: lo: 0 hi: 10194 @@ -22,7 +22,7 @@ outputs: - Literal: Integer: - I8 - - "12" + - 1_2 - span: lo: 0 hi: 5 @@ -30,7 +30,7 @@ outputs: - Literal: Integer: - I8 - - "123" + - 12_3 - span: lo: 0 hi: 6 @@ -38,7 +38,7 @@ outputs: - Literal: Integer: - I8 - - "1234" + - 12_3_4 - span: lo: 0 hi: 8 @@ -46,7 +46,7 @@ outputs: - Literal: Integer: - I8 - - "12345" + - 12_3_4_5 - span: lo: 0 hi: 10 @@ -63,7 +63,7 @@ outputs: - Literal: Integer: - I16 - - "1234" + - 1_234 - span: lo: 0 hi: 8 @@ -71,7 +71,7 @@ outputs: - Literal: Integer: - I16 - - "1234" + - 12_34 - span: lo: 0 hi: 8 @@ -79,7 +79,7 @@ outputs: - Literal: Integer: - I16 - - "1234" + - 123_4 - span: lo: 0 hi: 8 @@ -87,7 +87,7 @@ outputs: - Literal: Integer: - I16 - - "1234" + - 12_3_4 - span: lo: 0 hi: 9 @@ -96,7 +96,7 @@ outputs: - Literal: Integer: - I32 - - "123" + - 1_2_3 - span: lo: 0 hi: 8 @@ -104,7 +104,7 @@ outputs: - Literal: Integer: - I32 - - "123" + - 1__2__3 - span: lo: 0 hi: 10 @@ -112,7 +112,7 @@ outputs: - Literal: Integer: - I32 - - "000000" + - 0__0__0000 - span: lo: 0 hi: 13 @@ -120,7 +120,7 @@ outputs: - Literal: Integer: - I32 - - "02930932" + - 0_2930_932_________________ - span: lo: 0 hi: 30 @@ -128,7 +128,7 @@ outputs: - Literal: Integer: - I32 - - "00" + - 0_0 - span: lo: 0 hi: 6 @@ -136,7 +136,7 @@ outputs: - Literal: Integer: - I32 - - "000001034043240" + - 000001034043240__________________________________________________________________________ - span: lo: 0 hi: 92 @@ -153,7 +153,7 @@ outputs: - Literal: Integer: - I64 - - "1234567890123456" + - 1_234567890123456 - span: lo: 0 hi: 20 @@ -161,7 +161,7 @@ outputs: - Literal: Integer: - I64 - - "1234567890123456" + - 12_34567890123456 - span: lo: 0 hi: 20 @@ -169,7 +169,7 @@ outputs: - Literal: Integer: - I64 - - "1234567890123456" + - 123456789012_3456 - span: lo: 0 hi: 20 @@ -177,7 +177,7 @@ outputs: - Literal: Integer: - I64 - - "1234567890123456" + - 1234567890_123456 - span: lo: 0 hi: 20 @@ -194,7 +194,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 1_2345678901234567890123456789012 - span: lo: 0 hi: 37 @@ -202,7 +202,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 12_345678901234567890123456789012 - span: lo: 0 hi: 37 @@ -210,7 +210,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 1234567890123456789012345678_9012 - span: lo: 0 hi: 37 @@ -218,7 +218,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 12345678901234567890_123456789012 - span: lo: 0 hi: 37 @@ -235,7 +235,7 @@ outputs: - Literal: Integer: - U8 - - "12" + - 1_2 - span: lo: 0 hi: 5 @@ -243,7 +243,7 @@ outputs: - Literal: Integer: - U8 - - "123" + - 12_3 - span: lo: 0 hi: 6 @@ -251,7 +251,7 @@ outputs: - Literal: Integer: - U8 - - "1234" + - 12_3_4 - span: lo: 0 hi: 8 @@ -259,7 +259,7 @@ outputs: - Literal: Integer: - U8 - - "12345" + - 12_3_4_5 - span: lo: 0 hi: 10 @@ -276,7 +276,7 @@ outputs: - Literal: Integer: - U16 - - "1234" + - 1_234 - span: lo: 0 hi: 8 @@ -284,7 +284,7 @@ outputs: - Literal: Integer: - U16 - - "1234" + - 12_34 - span: lo: 0 hi: 8 @@ -292,7 +292,7 @@ outputs: - Literal: Integer: - U16 - - "1234" + - 123_4 - span: lo: 0 hi: 8 @@ -300,7 +300,7 @@ outputs: - Literal: Integer: - U16 - - "1234" + - 12_3_4 - span: lo: 0 hi: 9 @@ -317,7 +317,7 @@ outputs: - Literal: Integer: - U32 - - "12345678" + - 1_2345678 - span: lo: 0 hi: 12 @@ -325,7 +325,7 @@ outputs: - Literal: Integer: - U32 - - "12345678" + - 12_345678 - span: lo: 0 hi: 12 @@ -333,7 +333,7 @@ outputs: - Literal: Integer: - U32 - - "12345678" + - 1234567_8 - span: lo: 0 hi: 12 @@ -341,7 +341,7 @@ outputs: - Literal: Integer: - U32 - - "12345678" + - 1234_5678 - span: lo: 0 hi: 12 @@ -358,7 +358,7 @@ outputs: - Literal: Integer: - U64 - - "1234567890123456" + - 1_234567890123456 - span: lo: 0 hi: 20 @@ -366,7 +366,7 @@ outputs: - Literal: Integer: - U64 - - "1234567890123456" + - 12_34567890123456 - span: lo: 0 hi: 20 @@ -374,7 +374,7 @@ outputs: - Literal: Integer: - U64 - - "1234567890123456" + - 123456789012_3456 - span: lo: 0 hi: 20 @@ -382,7 +382,7 @@ outputs: - Literal: Integer: - U64 - - "1234567890123456" + - 1234567890_123456 - span: lo: 0 hi: 20 @@ -399,7 +399,7 @@ outputs: - Literal: Integer: - U128 - - "12345678901234567890123456789012" + - 1_2345678901234567890123456789012 - span: lo: 0 hi: 37 @@ -407,7 +407,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 12_345678901234567890123456789012 - span: lo: 0 hi: 37 @@ -415,7 +415,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 1234567890123456789012345678_9012 - span: lo: 0 hi: 37 @@ -423,7 +423,7 @@ outputs: - Literal: Integer: - I128 - - "12345678901234567890123456789012" + - 12345678901234567890_123456789012 - span: lo: 0 hi: 37 @@ -438,28 +438,28 @@ outputs: - 0 - Literal: Field: - - "87377802873778028737780287377802873778028737780287377802873778028737780287377802" + - 8737780287___3778028737780287377802873778028737780287377802873778028737780287377802 - span: lo: 0 hi: 88 - 0 - Literal: Field: - - "8737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802" + - 8__737780287377___________80287377802873778028737780287377802873778028737______78028737780287377802873778028737780287____37780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802 - span: lo: 0 hi: 428 - 0 - Literal: Field: - - "340130024" + - 340130____024 - span: lo: 0 hi: 18 - 0 - Literal: Field: - - "158951116" + - 15_8951116____ - span: lo: 0 hi: 19 @@ -467,49 +467,49 @@ outputs: - "" - Literal: Scalar: - - "724940549" + - 72___4940549 - span: lo: 0 hi: 18 - 0 - Literal: Scalar: - - "487101620" + - 48710162___0 - span: lo: 0 hi: 18 - 0 - Literal: Scalar: - - "100234" + - 100__234 - span: lo: 0 hi: 14 - 0 - Literal: Scalar: - - "1234" + - 1_234 - span: lo: 0 hi: 11 - 0 - Literal: Scalar: - - "1234" + - 12_34 - span: lo: 0 hi: 11 - 0 - Literal: Scalar: - - "1234" + - 123_4 - span: lo: 0 hi: 11 - 0 - Literal: Scalar: - - "1234" + - 12_3_4 - span: lo: 0 hi: 12 @@ -518,7 +518,7 @@ outputs: - Literal: Group: Single: - - "199375617" + - 19____9__3756___17 - span: lo: 0 hi: 23 @@ -526,7 +526,7 @@ outputs: - Literal: Group: Single: - - "680337189" + - 68______03______3718____9__ - span: lo: 0 hi: 32 @@ -534,7 +534,7 @@ outputs: - Literal: Group: Single: - - "81879931" + - 818__79931__ - span: lo: 0 hi: 17 @@ -542,7 +542,7 @@ outputs: - Literal: Group: Single: - - "893693281" + - 8__9369328__1 - span: lo: 0 hi: 18 @@ -550,7 +550,7 @@ outputs: - Literal: Group: Single: - - "87377802" + - 873__778____02 - span: lo: 0 hi: 19 @@ -558,7 +558,7 @@ outputs: - Literal: Group: Single: - - "84699261" + - 84699__261 - span: lo: 0 hi: 15 @@ -566,7 +566,7 @@ outputs: - Literal: Group: Single: - - "292826090" + - 29__282609__0 - span: lo: 0 hi: 18 @@ -577,13 +577,13 @@ outputs: Tuple: x: Number: - - "123" + - 1___2__3 - span: lo: 1 hi: 9 y: Number: - - "-456" + - "-4_5__6" - span: lo: 11 hi: 17 @@ -596,13 +596,13 @@ outputs: Tuple: x: Number: - - "-123" + - "-12___3" - span: lo: 2 hi: 8 y: Number: - - "456" + - 456__ - span: lo: 9 hi: 14 @@ -615,13 +615,13 @@ outputs: Tuple: x: Number: - - "-123" + - "-12__3" - span: lo: 2 hi: 7 y: Number: - - "456" + - 45______6 - span: lo: 8 hi: 17 @@ -634,7 +634,7 @@ outputs: Tuple: x: Number: - - "123" + - 1__23 - span: lo: 1 hi: 6 @@ -648,7 +648,7 @@ outputs: Tuple: x: Number: - - "123" + - 12__3 - span: lo: 1 hi: 6 @@ -662,7 +662,7 @@ outputs: Tuple: x: Number: - - "0123" + - 0___1_2_3 - span: lo: 1 hi: 10 @@ -676,7 +676,7 @@ outputs: Tuple: x: Number: - - "123" + - 12_3 - span: lo: 1 hi: 5 @@ -690,7 +690,7 @@ outputs: Tuple: x: Number: - - "0123" + - 0____123 - span: lo: 1 hi: 9 @@ -704,7 +704,7 @@ outputs: Tuple: x: Number: - - "123" + - 12_3 - span: lo: 1 hi: 5 @@ -718,7 +718,7 @@ outputs: Tuple: x: Number: - - "123" + - 12__3 - span: lo: 1 hi: 6 @@ -733,7 +733,7 @@ outputs: x: SignHigh y: Number: - - "345" + - 345__ - span: lo: 4 hi: 9 @@ -747,7 +747,7 @@ outputs: x: Inferred y: Number: - - "345" + - 34_5 - span: lo: 4 hi: 8 @@ -761,7 +761,7 @@ outputs: x: SignHigh y: Number: - - "345" + - 345_ - span: lo: 4 hi: 8 @@ -775,7 +775,7 @@ outputs: x: SignLow y: Number: - - "345" + - 34_____5 - span: lo: 4 hi: 12 @@ -789,7 +789,7 @@ outputs: x: SignHigh y: Number: - - "345" + - 3_45 - span: lo: 4 hi: 8 @@ -803,7 +803,7 @@ outputs: x: SignLow y: Number: - - "35" + - 3_5 - span: lo: 4 hi: 7 @@ -817,7 +817,7 @@ outputs: x: Inferred y: Number: - - "3452" + - 345_2 - span: lo: 4 hi: 9 @@ -830,13 +830,13 @@ outputs: Tuple: x: Number: - - "12" + - 1_2 - span: lo: 1 hi: 4 y: Number: - - "34" + - 3_4 - span: lo: 5 hi: 8 @@ -849,13 +849,13 @@ outputs: Tuple: x: Number: - - "123" + - 12_3 - span: lo: 1 hi: 5 y: Number: - - "45" + - 4_5 - span: lo: 6 hi: 9 @@ -868,13 +868,13 @@ outputs: Tuple: x: Number: - - "123" + - 12_3 - span: lo: 1 hi: 5 y: Number: - - "456" + - 45_6 - span: lo: 6 hi: 10 @@ -887,13 +887,13 @@ outputs: Tuple: x: Number: - - "123" + - 1_2_3 - span: lo: 1 hi: 6 y: Number: - - "456" + - 4_5_6 - span: lo: 7 hi: 12 @@ -906,13 +906,13 @@ outputs: Tuple: x: Number: - - "1234" + - 12_3_4 - span: lo: 1 hi: 7 y: Number: - - "567" + - 56_7 - span: lo: 8 hi: 12 diff --git a/tests/expectations/parser/statement/definition_fail.out b/tests/expectations/parser/statement/definition_fail.out index 7ae81b45a0..4743d40633 100644 --- a/tests/expectations/parser/statement/definition_fail.out +++ b/tests/expectations/parser/statement/definition_fail.out @@ -46,4 +46,4 @@ outputs: - "Error [EPAR0370005]: expected : -- found '='\n --> test:1:9\n |\n 1 | let (x) = ...;\n | ^" - "Error [EPAR0370029]: A tuple expression must have at least two elements.\n --> test:1:5\n |\n 1 | let (x,) = ...;\n | ^^^^" - "Error [EPAR0370009]: unexpected string: expected 'expression', found '_'\n --> test:1:5\n |\n 1 | let _1: u8 = 1u8;\n | ^" - - "Error [EPAR0370017]: Could not parse the implicit value: 1091.\n --> test:1:5\n |\n 1 | let 1___091: u8 = 12u8;\n | ^^^^^^^" + - "Error [EPAR0370017]: Could not parse the implicit value: 1___091.\n --> test:1:5\n |\n 1 | let 1___091: u8 = 12u8;\n | ^^^^^^^" diff --git a/tests/expectations/parser/unreachable/eat_int.out b/tests/expectations/parser/unreachable/eat_int.out index 8a9b63f643..a5cb75fbab 100644 --- a/tests/expectations/parser/unreachable/eat_int.out +++ b/tests/expectations/parser/unreachable/eat_int.out @@ -2,56 +2,56 @@ namespace: ParseStatement expectation: Fail outputs: - - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:5\n |\n 1 | x.0_;\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:6\n |\n 1 | x.0_0;\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ';'\n --> test:1:5\n |\n 1 | x.01;\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '.'\n --> test:1:5\n |\n 1 | x.0_.\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found 'import'\n --> test:1:5\n |\n 1 | x.0_import\n | ^^^^^^" - - "Error [EPAR0370005]: expected integer literal -- found ','\n --> test:1:5\n |\n 1 | x.0_,\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '*'\n --> test:1:5\n |\n 1 | x.0_*\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '+'\n --> test:1:5\n |\n 1 | x.0_+\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '-'\n --> test:1:5\n |\n 1 | x.0_-\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '/'\n --> test:1:5\n |\n 1 | x.0_/\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '['\n --> test:1:5\n |\n 1 | x.0_[\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ']'\n --> test:1:5\n |\n 1 | x.0_]\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '{'\n --> test:1:5\n |\n 1 | x.0_{\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '}'\n --> test:1:5\n |\n 1 | x.0_}\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '('\n --> test:1:5\n |\n 1 | x.0_(\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ')'\n --> test:1:5\n |\n 1 | x.0_)\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ':'\n --> test:1:5\n |\n 1 | x.0_:\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '::'\n --> test:1:5\n |\n 1 | x.0_::\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found '?'\n --> test:1:5\n |\n 1 | x.0_?\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found ''\n --> test:1:3\n |\n 1 | x.0__\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found '='\n --> test:1:5\n |\n 1 | x.0_=\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '=='\n --> test:1:5\n |\n 1 | x.0_==\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found '!'\n --> test:1:5\n |\n 1 | x.0_!\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '!='\n --> test:1:5\n |\n 1 | x.0_!=\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '>='\n --> test:1:5\n |\n 1 | x.0_>=\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found '<'\n --> test:1:5\n |\n 1 | x.0_<\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '<='\n --> test:1:5\n |\n 1 | x.0_<=\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found '..'\n --> test:1:5\n |\n 1 | x.0_..\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found 'as'\n --> test:1:5\n |\n 1 | x.0_as\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found 'console'\n --> test:1:5\n |\n 1 | x.0_console\n | ^^^^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'const'\n --> test:1:5\n |\n 1 | x.0_const\n | ^^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'let'\n --> test:1:5\n |\n 1 | x.0_let\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'for'\n --> test:1:5\n |\n 1 | x.0_for\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'if'\n --> test:1:5\n |\n 1 | x.0_if\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found 'else'\n --> test:1:5\n |\n 1 | x.0_else\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'i8'\n --> test:1:5\n |\n 1 | x.0_i8\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found 'i16'\n --> test:1:5\n |\n 1 | x.0_i16\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'i32'\n --> test:1:5\n |\n 1 | x.0_i32\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'i64'\n --> test:1:5\n |\n 1 | x.0_i64\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'i128'\n --> test:1:5\n |\n 1 | x.0_i128\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'u8'\n --> test:1:5\n |\n 1 | x.0_u8\n | ^^" - - "Error [EPAR0370005]: expected integer literal -- found 'u16'\n --> test:1:5\n |\n 1 | x.0_u16\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'u32'\n --> test:1:5\n |\n 1 | x.0_u32\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'u64'\n --> test:1:5\n |\n 1 | x.0_u64\n | ^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'u128'\n --> test:1:5\n |\n 1 | x.0_u128\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found '&'\n --> test:1:5\n |\n 1 | x.0_&\n | ^" - - "Error [EPAR0370005]: expected integer literal -- found 'return'\n --> test:1:5\n |\n 1 | x.0_return\n | ^^^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'self'\n --> test:1:5\n |\n 1 | x.0_self\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'Self'\n --> test:1:5\n |\n 1 | x.0_Self\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'true'\n --> test:1:5\n |\n 1 | x.0_true\n | ^^^^" - - "Error [EPAR0370005]: expected integer literal -- found 'false'\n --> test:1:5\n |\n 1 | x.0_false\n | ^^^^^" + - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:5\n |\n 1 | x.0_;\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:6\n |\n 1 | x.0_0;\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:5\n |\n 1 | x.01;\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '.'\n --> test:1:5\n |\n 1 | x.0_.\n | ^" + - "Error [EPAR0370033]: expected whole number -- found 'import'\n --> test:1:5\n |\n 1 | x.0_import\n | ^^^^^^" + - "Error [EPAR0370033]: expected whole number -- found ','\n --> test:1:5\n |\n 1 | x.0_,\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '*'\n --> test:1:5\n |\n 1 | x.0_*\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '+'\n --> test:1:5\n |\n 1 | x.0_+\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '-'\n --> test:1:5\n |\n 1 | x.0_-\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '/'\n --> test:1:5\n |\n 1 | x.0_/\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '['\n --> test:1:5\n |\n 1 | x.0_[\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ']'\n --> test:1:5\n |\n 1 | x.0_]\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '{'\n --> test:1:5\n |\n 1 | x.0_{\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '}'\n --> test:1:5\n |\n 1 | x.0_}\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '('\n --> test:1:5\n |\n 1 | x.0_(\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ')'\n --> test:1:5\n |\n 1 | x.0_)\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ':'\n --> test:1:5\n |\n 1 | x.0_:\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '::'\n --> test:1:5\n |\n 1 | x.0_::\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found '?'\n --> test:1:5\n |\n 1 | x.0_?\n | ^" + - "Error [EPAR0370033]: expected whole number -- found ''\n --> test:1:3\n |\n 1 | x.0__\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found '='\n --> test:1:5\n |\n 1 | x.0_=\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '=='\n --> test:1:5\n |\n 1 | x.0_==\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found '!'\n --> test:1:5\n |\n 1 | x.0_!\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '!='\n --> test:1:5\n |\n 1 | x.0_!=\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '>='\n --> test:1:5\n |\n 1 | x.0_>=\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found '<'\n --> test:1:5\n |\n 1 | x.0_<\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '<='\n --> test:1:5\n |\n 1 | x.0_<=\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370033]: expected whole number -- found '..'\n --> test:1:5\n |\n 1 | x.0_..\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found 'as'\n --> test:1:5\n |\n 1 | x.0_as\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found 'console'\n --> test:1:5\n |\n 1 | x.0_console\n | ^^^^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'const'\n --> test:1:5\n |\n 1 | x.0_const\n | ^^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'let'\n --> test:1:5\n |\n 1 | x.0_let\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'for'\n --> test:1:5\n |\n 1 | x.0_for\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'if'\n --> test:1:5\n |\n 1 | x.0_if\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found 'else'\n --> test:1:5\n |\n 1 | x.0_else\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'i8'\n --> test:1:5\n |\n 1 | x.0_i8\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found 'i16'\n --> test:1:5\n |\n 1 | x.0_i16\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'i32'\n --> test:1:5\n |\n 1 | x.0_i32\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'i64'\n --> test:1:5\n |\n 1 | x.0_i64\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'i128'\n --> test:1:5\n |\n 1 | x.0_i128\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'u8'\n --> test:1:5\n |\n 1 | x.0_u8\n | ^^" + - "Error [EPAR0370033]: expected whole number -- found 'u16'\n --> test:1:5\n |\n 1 | x.0_u16\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'u32'\n --> test:1:5\n |\n 1 | x.0_u32\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'u64'\n --> test:1:5\n |\n 1 | x.0_u64\n | ^^^" + - "Error [EPAR0370033]: expected whole number -- found 'u128'\n --> test:1:5\n |\n 1 | x.0_u128\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found '&'\n --> test:1:5\n |\n 1 | x.0_&\n | ^" + - "Error [EPAR0370033]: expected whole number -- found 'return'\n --> test:1:5\n |\n 1 | x.0_return\n | ^^^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'self'\n --> test:1:5\n |\n 1 | x.0_self\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'Self'\n --> test:1:5\n |\n 1 | x.0_Self\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'true'\n --> test:1:5\n |\n 1 | x.0_true\n | ^^^^" + - "Error [EPAR0370033]: expected whole number -- found 'false'\n --> test:1:5\n |\n 1 | x.0_false\n | ^^^^^" diff --git a/tests/tests/compiler/integers/i8/add.leo b/tests/tests/compiler/integers/i8/add.leo index 5f50a79d54..4b41b8a01f 100644 --- a/tests/tests/compiler/integers/i8/add.leo +++ b/tests/tests/compiler/integers/i8/add.leo @@ -5,6 +5,6 @@ expectation: Pass program test.aleo { transition main(a: i8, b: i8, c: i8) -> bool { - return a + b == c; + return a + b + 1_1i8 + 1______1i8 == c + 1i8; } } diff --git a/tests/tests/compiler/statements/block.leo b/tests/tests/compiler/statements/block.leo index 6c1a3768e1..677409897c 100644 --- a/tests/tests/compiler/statements/block.leo +++ b/tests/tests/compiler/statements/block.leo @@ -3,13 +3,13 @@ namespace: Compile expectation: Pass */ -program test.aleo { +program test.aleo { transition main(x: u32) -> bool { let y: u32 = x; - + { y = y + 5u32; } - + return y == 8u32; - }} + }} \ No newline at end of file diff --git a/tests/tests/compiler/statements/loop_decreasing_fail.leo b/tests/tests/compiler/statements/loop_decreasing_fail.leo new file mode 100644 index 0000000000..33aa0d45c3 --- /dev/null +++ b/tests/tests/compiler/statements/loop_decreasing_fail.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Fail +*/ + +program test.aleo { + transition main(x: u32) -> bool { + + let count: i8 = 0i8; + for i: i8 in 10i8..5i8 { + count += 1i8; + } + + return true; + } +} \ No newline at end of file diff --git a/tests/tests/compiler/statements/underscore_for_loop.leo b/tests/tests/compiler/statements/underscore_for_loop.leo new file mode 100644 index 0000000000..3faa89a665 --- /dev/null +++ b/tests/tests/compiler/statements/underscore_for_loop.leo @@ -0,0 +1,70 @@ +/* +namespace: Compile +expectation: Pass +*/ + +program test.aleo { + transition main(x: u32) -> bool { + + // For i8 + let count_i8: i8 = 0i8; + for i: i8 in 11i8..0__________5i8 { + count_i8 += 1i8; + } + + // For i16 + let count_i16: i16 = 0i16; + for i: i16 in 1i16..5i16 { + count_i16 += 1i16; + } + + // For i32 + let count_i32: i32 = 0i32; + for i: i32 in 1i32..5i32 { + count_i32 += 1i32; + } + + // For i64 + let count_i64: i64 = 0i64; + for i: i64 in 1i64..5i64 { + count_i64 += 1i64; + } + + // For i128 + let count_i128: i128 = 0i128; + for i: i128 in 1i128..5i128 { + count_i128 += 1i128; + } + + // For u8 + let count_u8: u8 = 0u8; + for i: u8 in 1u8..5u8 { + count_u8 += 1u8; + } + + // For u16 + let count_u16: u16 = 0u16; + for i: u16 in 1u16..5u16 { + count_u16 += 1u16; + } + + // For u32 + let count_u32: u32 = 0u32; + for i: u32 in 1u32..5u32 { + count_u32 += 1u32; + } + + // For u64 + let count_u64: u64 = 0u64; + for i: u64 in 1u64..5u64 { + count_u64 += 1u64; + } + + // For u128 + let count_u128: u128 = 0u128; + for i: u128 in 0_0000_0000_0000_0001u128..5u128 { + count_u128 += 1u128; + } + return true; + } +} \ No newline at end of file From 4308d598e293309f6c61bfe42ab7269453f786b6 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:29:23 -0700 Subject: [PATCH 4/9] running all tests and updating expectation files --- compiler/parser/src/parser/context.rs | 7 +++- .../src/type_checking/check_statements.rs | 8 ++-- .../compiler/statements/block.out | 14 +++---- .../iteration_bound_too_large_fail.out | 2 +- .../loop_non_literal_bound_fail.out | 2 +- .../statements/underscore_for_loop.out | 12 +++--- .../statements/underscore_for_loop.leo | 38 +++++++++---------- 7 files changed, 43 insertions(+), 40 deletions(-) diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index 553a87b11b..c5a885bd8c 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -162,7 +162,12 @@ impl<'a> ParserContext<'a> { self.bump(); // Reject value if the length is over 2 and the first character is 0 if (value.len() > 1 && value.starts_with('0')) || value.contains('_') { - return Err(ParserError::tuple_index_must_be_whole_number(&self.token.token, "whole number", self.token.span).into()); + return Err(ParserError::tuple_index_must_be_whole_number( + &self.token.token, + "whole number", + self.token.span, + ) + .into()); } Ok((PositiveNumber { value }, self.prev_token.span)) diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index c1fe8a757a..761276b030 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -274,8 +274,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { // Note that this check is needed because the pass attempts to make progress, even though the literal may be invalid. if let Ok(value) = Value::try_from(literal) { input.start_value.replace(Some(value)); - } - else { + } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span())); } } else { @@ -289,14 +288,14 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { // Note that this check is needed because the pass attempts to make progress, even though the literal may be invalid. if let Ok(value) = Value::try_from(literal) { input.stop_value.replace(Some(value)); - } - else { + } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); } } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); } + // Ensure loop bounds are not decreasing. if match (input.start_value.borrow().as_ref(), input.stop_value.borrow().as_ref()) { (Some(Value::I8(lower_bound, _)), Some(Value::I8(upper_bound, _))) => lower_bound >= upper_bound, (Some(Value::I16(lower_bound, _)), Some(Value::I16(upper_bound, _))) => lower_bound >= upper_bound, @@ -315,7 +314,6 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { } { self.emit_err(TypeCheckerError::loop_range_decreasing(input.stop.span())); } - } fn visit_return(&mut self, input: &'a ReturnStatement) { diff --git a/tests/expectations/compiler/statements/block.out b/tests/expectations/compiler/statements/block.out index 42810ede58..d1930db75a 100644 --- a/tests/expectations/compiler/statements/block.out +++ b/tests/expectations/compiler/statements/block.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 6fbf3a5297e1c0ac385d9a0bca37461e3f05db150256c4805c933b995291e8a8 - unrolled_ast: 0b30fd3c36c48eacdec271e2be37ed26d0a903a62175524283ac214aee38e861 - ssa_ast: a5246ba65141147bdf42b84a46efbd81e97ede4fddb70cf08e758ab0b4908ed0 - flattened_ast: da5289263185bf3629befaa4571978fc7a59d27f8af2da7e5c47181509f73eaf - inlined_ast: da5289263185bf3629befaa4571978fc7a59d27f8af2da7e5c47181509f73eaf - dce_ast: c05d81f5bbd7df8fa456f8dad5aff1d1ca169d9defbd84829698895f452826f2 - bytecode: 1a9f3c92be71c05ccb8a22286f99a0ba1e88d1f580dec2c7305ec17b08e0089a + - - initial_ast: 1d588d3765da4c9534dbe6f57ec671ff28232b48bfb80c3777799db1267156d5 + unrolled_ast: 1d588d3765da4c9534dbe6f57ec671ff28232b48bfb80c3777799db1267156d5 + ssa_ast: 5f52523779c4b3c1e2c05e43d9dba23227b44b52c4c67616454fdc6980a309cb + flattened_ast: 99f116e7cab7619853f0481493dabb8044d73980ec3e4f45aecbd231d5bedf0b + inlined_ast: 99f116e7cab7619853f0481493dabb8044d73980ec3e4f45aecbd231d5bedf0b + dce_ast: 99f116e7cab7619853f0481493dabb8044d73980ec3e4f45aecbd231d5bedf0b + bytecode: 9f2bbabd0f858db6e5f4e529fdd5e246023994bf27bbabe6dc1aa6bbf8bf5cfd warnings: "" diff --git a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out index 966a8f720d..761847163f 100644 --- a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out +++ b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372079]: The loop bounds must be same type\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out b/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out index b905462e13..a92d371e38 100644 --- a/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out +++ b/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\n" + - "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\nError [ETYC0372079]: The loop bounds must be same type\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\n" diff --git a/tests/expectations/compiler/statements/underscore_for_loop.out b/tests/expectations/compiler/statements/underscore_for_loop.out index 76e3f5eb69..78e2c02885 100644 --- a/tests/expectations/compiler/statements/underscore_for_loop.out +++ b/tests/expectations/compiler/statements/underscore_for_loop.out @@ -2,11 +2,11 @@ namespace: Compile expectation: Pass outputs: - - - initial_ast: 0cbd0b999474cce80a0958de212e0cfac204c3b3e8e70efe017754a8085971d3 - unrolled_ast: 8462d3bb0f91c5ae618402dfb9ae88345b5b271e88febea430a6c8b174f30573 - ssa_ast: eb19911f0f9788d733db228c52493ec9f4be8a4616dd3b6268f254707190830d - flattened_ast: c36e658478aeed0e41f2001dacbd8e5c2d5d59a25d4c3b7d2827034fe9404080 - inlined_ast: c36e658478aeed0e41f2001dacbd8e5c2d5d59a25d4c3b7d2827034fe9404080 - dce_ast: 51157d270af2da9d52fc6d514ccfe2023d8c11e475949e41696c4527a6b909c8 + - - initial_ast: 7a88b27e12cbba00a60c6f0d25814df5fbb4d6878a120c1508fc92adac6bb094 + unrolled_ast: 0742c151a297119b19e1debc977b482fbba534d15f1a6f424e8b88a593d86da7 + ssa_ast: f25a9fc5ffb10a442d1c343d45c4ab3e2a8a3aead5be07dd4a4109ee4e8dbf43 + flattened_ast: 960941bf6e20797b225260976a975ab1ee0bb2357f6215168377f094d01c6dba + inlined_ast: 960941bf6e20797b225260976a975ab1ee0bb2357f6215168377f094d01c6dba + dce_ast: b8851a63f706ce2a4aff3e73653f0f07b5b9ccaa147306baec1bfd997cc5fa9d bytecode: 61cc464cdc1104635ea399648d62a06b112dc3462634b3f992151c6e5572d6f7 warnings: "" diff --git a/tests/tests/compiler/statements/underscore_for_loop.leo b/tests/tests/compiler/statements/underscore_for_loop.leo index 3faa89a665..4568699fc9 100644 --- a/tests/tests/compiler/statements/underscore_for_loop.leo +++ b/tests/tests/compiler/statements/underscore_for_loop.leo @@ -7,62 +7,62 @@ program test.aleo { transition main(x: u32) -> bool { // For i8 - let count_i8: i8 = 0i8; - for i: i8 in 11i8..0__________5i8 { + let count_i8: i8 = 0__0i8 + 1_9i8; + for i: i8 in 0______1i8..0__________5i8 { count_i8 += 1i8; } // For i16 - let count_i16: i16 = 0i16; + let count_i16: i16 = 0__0i16 + 0__1_9i16; for i: i16 in 1i16..5i16 { count_i16 += 1i16; } // For i32 - let count_i32: i32 = 0i32; - for i: i32 in 1i32..5i32 { + let count_i32: i32 = 0__0i32 + 0__0__1_9i32; + for i: i32 in 000___0_1i32..0_05______1i32 { count_i32 += 1i32; } // For i64 - let count_i64: i64 = 0i64; - for i: i64 in 1i64..5i64 { + let count_i64: i64 = 0__0i64 * 000_0__1_9i64; + for i: i64 in 000__1___1i64..1___000_5i64 { count_i64 += 1i64; } // For i128 - let count_i128: i128 = 0i128; - for i: i128 in 1i128..5i128 { + let count_i128: i128 = 000_0_000_0_0__0i128 + 000_0_1_9i128; + for i: i128 in 000___0001__0________1i128..000_500______i128 { count_i128 += 1i128; } // For u8 - let count_u8: u8 = 0u8; - for i: u8 in 1u8..5u8 { + let count_u8: u8 = 000_0_0__0u8 + 000_0_1_9u8; + for i: u8 in 000___1u8..00_5u8 { count_u8 += 1u8; } // For u16 - let count_u16: u16 = 0u16; - for i: u16 in 1u16..5u16 { + let count_u16: u16 = 0__000_0_0u16 + 000_0_1_9u16; + for i: u16 in 01u16..000______1______5u16 { count_u16 += 1u16; } // For u32 - let count_u32: u32 = 0u32; - for i: u32 in 1u32..5u32 { + let count_u32: u32 = 0000_0_000_0___0u32 + 000_0_1_9u32; + for i: u32 in 000___11u32..00000______1_5u32 { count_u32 += 1u32; } // For u64 - let count_u64: u64 = 0u64; - for i: u64 in 1u64..5u64 { + let count_u64: u64 = 0_000_0__0u64 + 000_0_000_0_000_0_000_0_1_9u64; + for i: u64 in 0___01u64..0____1____5u64 { count_u64 += 1u64; } // For u128 - let count_u128: u128 = 0u128; - for i: u128 in 0_0000_0000_0000_0001u128..5u128 { + let count_u128: u128 = 0__000_0_000_0_0u128 + 000_0_000_0_1_9u128; + for i: u128 in 0_0000_0000_0000_0001u128..0000_____00000___1_____________5u128 { count_u128 += 1u128; } return true; From f4fee237581449b560ca0284cf931d377e2ef1ad Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:40:00 -0700 Subject: [PATCH 5/9] clippy fix --- compiler/ast/src/value/mod.rs | 2 +- compiler/passes/src/type_checking/check_expressions.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/ast/src/value/mod.rs b/compiler/ast/src/value/mod.rs index c30c03050d..8dcab4f5d0 100644 --- a/compiler/ast/src/value/mod.rs +++ b/compiler/ast/src/value/mod.rs @@ -878,7 +878,7 @@ impl TryFrom<&Literal> for Value { Literal::Scalar(string, span, _) => Self::Scalar(string.clone(), *span), Literal::String(string, span, _) => Self::String(string.clone(), *span), Literal::Integer(integer_type, raw_string, span, _) => { - let string = raw_string.replace("_", ""); + let string = raw_string.replace('_', ""); match integer_type { IntegerType::U8 => Self::U8(string.parse()?, *span), IntegerType::U16 => Self::U16(string.parse()?, *span), diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 536ba4b538..670774f79d 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -589,7 +589,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { fn visit_literal(&mut self, input: &'a Literal, expected: &Self::AdditionalInput) -> Self::Output { fn parse_integer_literal(handler: &Handler, raw_string: &String, span: Span, type_string: &str) { - let string = raw_string.replace("_", ""); + let string = raw_string.replace('_', ""); if string.parse::().is_err() { handler.emit_err(TypeCheckerError::invalid_int_value(string, type_string, span)); } From 90bb897130f16626bbcdaf06a66ea53128c67841 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:58:54 -0700 Subject: [PATCH 6/9] more clippy --- compiler/passes/src/type_checking/check_expressions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/passes/src/type_checking/check_expressions.rs b/compiler/passes/src/type_checking/check_expressions.rs index 670774f79d..fd1168efe1 100644 --- a/compiler/passes/src/type_checking/check_expressions.rs +++ b/compiler/passes/src/type_checking/check_expressions.rs @@ -588,7 +588,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { } fn visit_literal(&mut self, input: &'a Literal, expected: &Self::AdditionalInput) -> Self::Output { - fn parse_integer_literal(handler: &Handler, raw_string: &String, span: Span, type_string: &str) { + fn parse_integer_literal(handler: &Handler, raw_string: &str, span: Span, type_string: &str) { let string = raw_string.replace('_', ""); if string.parse::().is_err() { handler.emit_err(TypeCheckerError::invalid_int_value(string, type_string, span)); @@ -621,7 +621,7 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> { self.assert_and_return_type(Type::Integer(IntegerType::U128), expected, input.span()) } IntegerType::I8 => { - parse_integer_literal::(self.handler, &string, input.span(), "i8"); + parse_integer_literal::(self.handler, string, input.span(), "i8"); self.assert_and_return_type(Type::Integer(IntegerType::I8), expected, input.span()) } IntegerType::I16 => { From 550f43b0396cfe8951a42be493f0b758ddd8fc77 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Fri, 25 Aug 2023 09:49:53 -0700 Subject: [PATCH 7/9] Revisions (underscore to execute test, type checker error msg, spurious type error fix, revised tuple indexing test) --- compiler/parser/src/parser/context.rs | 1 - .../src/type_checking/check_statements.rs | 6 +- errors/src/errors/parser/parser_errors.rs | 4 +- .../errors/type_checker/type_checker_error.rs | 2 +- .../iteration_bound_too_large_fail.out | 2 +- .../statements/loop_decreasing_fail.out | 2 +- .../loop_non_literal_bound_fail.out | 2 +- tests/expectations/execution/counter.out | 14 +-- .../parser/unreachable/eat_int.out | 107 +++++++++--------- tests/tests/execution/counter.leo | 8 +- tests/tests/parser/unreachable/eat_int.leo | 2 + 11 files changed, 75 insertions(+), 75 deletions(-) diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index c5a885bd8c..271c93704e 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -164,7 +164,6 @@ impl<'a> ParserContext<'a> { if (value.len() > 1 && value.starts_with('0')) || value.contains('_') { return Err(ParserError::tuple_index_must_be_whole_number( &self.token.token, - "whole number", self.token.span, ) .into()); diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index 761276b030..b5331fac2d 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -307,10 +307,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { (Some(Value::U32(lower_bound, _)), Some(Value::U32(upper_bound, _))) => lower_bound >= upper_bound, (Some(Value::U64(lower_bound, _)), Some(Value::U64(upper_bound, _))) => lower_bound >= upper_bound, (Some(Value::U128(lower_bound, _)), Some(Value::U128(upper_bound, _))) => lower_bound >= upper_bound, - _ => { - self.emit_err(TypeCheckerError::loop_bound_type_mismatch(input.stop.span())); - false - } + // Note that type mismatch and non-literal errors will already be emitted by here. + _ => false } { self.emit_err(TypeCheckerError::loop_range_decreasing(input.stop.span())); } diff --git a/errors/src/errors/parser/parser_errors.rs b/errors/src/errors/parser/parser_errors.rs index 75e5a7b281..fa39d284b4 100644 --- a/errors/src/errors/parser/parser_errors.rs +++ b/errors/src/errors/parser/parser_errors.rs @@ -287,8 +287,8 @@ create_messages!( /// Enforce that tuple index must not have leading 0, or underscore in between digits @formatted tuple_index_must_be_whole_number { - args: (found: impl Display, expected: impl Display), - msg: format!("expected {expected} -- found '{found}'"), + args: (found: impl Display), + msg: format!("expected no underscores or leading zeros -- found '{found}'"), help: None, } ); diff --git a/errors/src/errors/type_checker/type_checker_error.rs b/errors/src/errors/type_checker/type_checker_error.rs index 100656ca59..05bddeb383 100644 --- a/errors/src/errors/type_checker/type_checker_error.rs +++ b/errors/src/errors/type_checker/type_checker_error.rs @@ -646,7 +646,7 @@ create_messages!( @formatted loop_range_decreasing { args: (), - msg: format!("The loop range must be decreasing."), + msg: format!("The loop range must be increasing."), help: None, } diff --git a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out index 761847163f..8a09f0aa83 100644 --- a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out +++ b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372079]: The loop bounds must be same type\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" diff --git a/tests/expectations/compiler/statements/loop_decreasing_fail.out b/tests/expectations/compiler/statements/loop_decreasing_fail.out index f8a8ca8481..94a4074b8e 100644 --- a/tests/expectations/compiler/statements/loop_decreasing_fail.out +++ b/tests/expectations/compiler/statements/loop_decreasing_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372078]: The loop range must be decreasing.\n --> compiler-test:7:28\n |\n 7 | for i: i8 in 10i8..5i8 {\n | ^^^\n" + - "Error [ETYC0372078]: The loop range must be increasing.\n --> compiler-test:7:28\n |\n 7 | for i: i8 in 10i8..5i8 {\n | ^^^\n" diff --git a/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out b/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out index a92d371e38..b905462e13 100644 --- a/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out +++ b/tests/expectations/compiler/statements/loop_non_literal_bound_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\nError [ETYC0372079]: The loop bounds must be same type\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\n" + - "Error [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:11:28\n |\n 11 | for i:u64 in 0u64..amount {\n | ^^^^^^\n" diff --git a/tests/expectations/execution/counter.out b/tests/expectations/execution/counter.out index ee5b1eedff..f066e5e200 100644 --- a/tests/expectations/execution/counter.out +++ b/tests/expectations/execution/counter.out @@ -2,13 +2,13 @@ namespace: Execute expectation: Pass outputs: - - - initial_ast: ff08a4a92839ebe43e5c035ff1ab8991da994f84b167630c9b26cdc8e30028e6 - unrolled_ast: ff08a4a92839ebe43e5c035ff1ab8991da994f84b167630c9b26cdc8e30028e6 - ssa_ast: 8fea46feeceac4607d6e09181bce795520d9403f0be606b049225459f10dfe47 - flattened_ast: 561824a5b5b1291ca6d59dace67780a62c1089536e895830f901c133fa74da85 - inlined_ast: 561824a5b5b1291ca6d59dace67780a62c1089536e895830f901c133fa74da85 - dce_ast: 561824a5b5b1291ca6d59dace67780a62c1089536e895830f901c133fa74da85 - bytecode: f6055195b401bef6fe1e686a256bb743941b1945b7fd4b8f1800aa83dc3b7495 + - - initial_ast: 437dad4042f19f778819ccccf9964ff9b6b701c2805417ba378d8d5d643d59bc + unrolled_ast: 437dad4042f19f778819ccccf9964ff9b6b701c2805417ba378d8d5d643d59bc + ssa_ast: 8f85576cdcb97f4b8c348fbad7ab7d85696cbdc1a26a19226903446785db9d20 + flattened_ast: 83c91f6cefa549e6fc788d063aa22446b095e1b37e8a20d2109c2ba10068230a + inlined_ast: 83c91f6cefa549e6fc788d063aa22446b095e1b37e8a20d2109c2ba10068230a + dce_ast: 83c91f6cefa549e6fc788d063aa22446b095e1b37e8a20d2109c2ba10068230a + bytecode: 18d3fa0f122b8bc035d12ca6fbca2d0d6c923e9ebde740ebf8101b34ee38102a warnings: "" results: dubble: diff --git a/tests/expectations/parser/unreachable/eat_int.out b/tests/expectations/parser/unreachable/eat_int.out index a5cb75fbab..01763b91ef 100644 --- a/tests/expectations/parser/unreachable/eat_int.out +++ b/tests/expectations/parser/unreachable/eat_int.out @@ -2,56 +2,57 @@ namespace: ParseStatement expectation: Fail outputs: - - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:5\n |\n 1 | x.0_;\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:6\n |\n 1 | x.0_0;\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ';'\n --> test:1:5\n |\n 1 | x.01;\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '.'\n --> test:1:5\n |\n 1 | x.0_.\n | ^" - - "Error [EPAR0370033]: expected whole number -- found 'import'\n --> test:1:5\n |\n 1 | x.0_import\n | ^^^^^^" - - "Error [EPAR0370033]: expected whole number -- found ','\n --> test:1:5\n |\n 1 | x.0_,\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '*'\n --> test:1:5\n |\n 1 | x.0_*\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '+'\n --> test:1:5\n |\n 1 | x.0_+\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '-'\n --> test:1:5\n |\n 1 | x.0_-\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '/'\n --> test:1:5\n |\n 1 | x.0_/\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '['\n --> test:1:5\n |\n 1 | x.0_[\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ']'\n --> test:1:5\n |\n 1 | x.0_]\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '{'\n --> test:1:5\n |\n 1 | x.0_{\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '}'\n --> test:1:5\n |\n 1 | x.0_}\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '('\n --> test:1:5\n |\n 1 | x.0_(\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ')'\n --> test:1:5\n |\n 1 | x.0_)\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ':'\n --> test:1:5\n |\n 1 | x.0_:\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '::'\n --> test:1:5\n |\n 1 | x.0_::\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found '?'\n --> test:1:5\n |\n 1 | x.0_?\n | ^" - - "Error [EPAR0370033]: expected whole number -- found ''\n --> test:1:3\n |\n 1 | x.0__\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found '='\n --> test:1:5\n |\n 1 | x.0_=\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '=='\n --> test:1:5\n |\n 1 | x.0_==\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found '!'\n --> test:1:5\n |\n 1 | x.0_!\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '!='\n --> test:1:5\n |\n 1 | x.0_!=\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '>='\n --> test:1:5\n |\n 1 | x.0_>=\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found '<'\n --> test:1:5\n |\n 1 | x.0_<\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '<='\n --> test:1:5\n |\n 1 | x.0_<=\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" - - "Error [EPAR0370033]: expected whole number -- found '..'\n --> test:1:5\n |\n 1 | x.0_..\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found 'as'\n --> test:1:5\n |\n 1 | x.0_as\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found 'console'\n --> test:1:5\n |\n 1 | x.0_console\n | ^^^^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'const'\n --> test:1:5\n |\n 1 | x.0_const\n | ^^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'let'\n --> test:1:5\n |\n 1 | x.0_let\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'for'\n --> test:1:5\n |\n 1 | x.0_for\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'if'\n --> test:1:5\n |\n 1 | x.0_if\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found 'else'\n --> test:1:5\n |\n 1 | x.0_else\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'i8'\n --> test:1:5\n |\n 1 | x.0_i8\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found 'i16'\n --> test:1:5\n |\n 1 | x.0_i16\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'i32'\n --> test:1:5\n |\n 1 | x.0_i32\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'i64'\n --> test:1:5\n |\n 1 | x.0_i64\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'i128'\n --> test:1:5\n |\n 1 | x.0_i128\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'u8'\n --> test:1:5\n |\n 1 | x.0_u8\n | ^^" - - "Error [EPAR0370033]: expected whole number -- found 'u16'\n --> test:1:5\n |\n 1 | x.0_u16\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'u32'\n --> test:1:5\n |\n 1 | x.0_u32\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'u64'\n --> test:1:5\n |\n 1 | x.0_u64\n | ^^^" - - "Error [EPAR0370033]: expected whole number -- found 'u128'\n --> test:1:5\n |\n 1 | x.0_u128\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found '&'\n --> test:1:5\n |\n 1 | x.0_&\n | ^" - - "Error [EPAR0370033]: expected whole number -- found 'return'\n --> test:1:5\n |\n 1 | x.0_return\n | ^^^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'self'\n --> test:1:5\n |\n 1 | x.0_self\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'Self'\n --> test:1:5\n |\n 1 | x.0_Self\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'true'\n --> test:1:5\n |\n 1 | x.0_true\n | ^^^^" - - "Error [EPAR0370033]: expected whole number -- found 'false'\n --> test:1:5\n |\n 1 | x.0_false\n | ^^^^^" + - "Error [EPAR0370009]: unexpected string: expected 'identifier', found '-'\n --> test:1:3\n |\n 1 | x.-12\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ';'\n --> test:1:5\n |\n 1 | x.0_;\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ';'\n --> test:1:6\n |\n 1 | x.0_0;\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ';'\n --> test:1:5\n |\n 1 | x.01;\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '.'\n --> test:1:5\n |\n 1 | x.0_.\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'import'\n --> test:1:5\n |\n 1 | x.0_import\n | ^^^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ','\n --> test:1:5\n |\n 1 | x.0_,\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '*'\n --> test:1:5\n |\n 1 | x.0_*\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '+'\n --> test:1:5\n |\n 1 | x.0_+\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '-'\n --> test:1:5\n |\n 1 | x.0_-\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '/'\n --> test:1:5\n |\n 1 | x.0_/\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '['\n --> test:1:5\n |\n 1 | x.0_[\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ']'\n --> test:1:5\n |\n 1 | x.0_]\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '{'\n --> test:1:5\n |\n 1 | x.0_{\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '}'\n --> test:1:5\n |\n 1 | x.0_}\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '('\n --> test:1:5\n |\n 1 | x.0_(\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ')'\n --> test:1:5\n |\n 1 | x.0_)\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ':'\n --> test:1:5\n |\n 1 | x.0_:\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '::'\n --> test:1:5\n |\n 1 | x.0_::\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '?'\n --> test:1:5\n |\n 1 | x.0_?\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found ''\n --> test:1:3\n |\n 1 | x.0__\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '='\n --> test:1:5\n |\n 1 | x.0_=\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '=='\n --> test:1:5\n |\n 1 | x.0_==\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '!'\n --> test:1:5\n |\n 1 | x.0_!\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '!='\n --> test:1:5\n |\n 1 | x.0_!=\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '>='\n --> test:1:5\n |\n 1 | x.0_>=\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '<'\n --> test:1:5\n |\n 1 | x.0_<\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '<='\n --> test:1:5\n |\n 1 | x.0_<=\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '>'\n --> test:1:5\n |\n 1 | x.0_>\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '..'\n --> test:1:5\n |\n 1 | x.0_..\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'as'\n --> test:1:5\n |\n 1 | x.0_as\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'console'\n --> test:1:5\n |\n 1 | x.0_console\n | ^^^^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'const'\n --> test:1:5\n |\n 1 | x.0_const\n | ^^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'let'\n --> test:1:5\n |\n 1 | x.0_let\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'for'\n --> test:1:5\n |\n 1 | x.0_for\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'if'\n --> test:1:5\n |\n 1 | x.0_if\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'else'\n --> test:1:5\n |\n 1 | x.0_else\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'i8'\n --> test:1:5\n |\n 1 | x.0_i8\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'i16'\n --> test:1:5\n |\n 1 | x.0_i16\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'i32'\n --> test:1:5\n |\n 1 | x.0_i32\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'i64'\n --> test:1:5\n |\n 1 | x.0_i64\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'i128'\n --> test:1:5\n |\n 1 | x.0_i128\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'u8'\n --> test:1:5\n |\n 1 | x.0_u8\n | ^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'u16'\n --> test:1:5\n |\n 1 | x.0_u16\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'u32'\n --> test:1:5\n |\n 1 | x.0_u32\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'u64'\n --> test:1:5\n |\n 1 | x.0_u64\n | ^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'u128'\n --> test:1:5\n |\n 1 | x.0_u128\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found '&'\n --> test:1:5\n |\n 1 | x.0_&\n | ^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'return'\n --> test:1:5\n |\n 1 | x.0_return\n | ^^^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'self'\n --> test:1:5\n |\n 1 | x.0_self\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'Self'\n --> test:1:5\n |\n 1 | x.0_Self\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'true'\n --> test:1:5\n |\n 1 | x.0_true\n | ^^^^" + - "Error [EPAR0370033]: expected no underscores or leading zeros -- found 'false'\n --> test:1:5\n |\n 1 | x.0_false\n | ^^^^^" diff --git a/tests/tests/execution/counter.leo b/tests/tests/execution/counter.leo index 42eb2dfcd8..a9bf637acc 100644 --- a/tests/tests/execution/counter.leo +++ b/tests/tests/execution/counter.leo @@ -19,10 +19,10 @@ program test.aleo { } finalize dubble(addr: address) { - let current_value: u64 = Mapping::get_or_use(counter, addr, 0u64); - Mapping::set(counter, addr, current_value + 1u64); + let current_value: u64 = Mapping::get_or_use(counter, addr, 0_0u64); + Mapping::set(counter, addr, current_value + 1__u64); current_value = Mapping::get(counter, addr); - Mapping::set(counter, addr, current_value + 1u64); + Mapping::set(counter, addr, current_value + 0___1u64); } transition unsafe_increment() { @@ -31,6 +31,6 @@ program test.aleo { finalize unsafe_increment(addr: address) { let current_value: u64 = Mapping::get(counter, addr); - Mapping::set(counter, addr, current_value + 1u64); + Mapping::set(counter, addr, current_value + 0__1u64); } } diff --git a/tests/tests/parser/unreachable/eat_int.leo b/tests/tests/parser/unreachable/eat_int.leo index 64bf596c69..869348728c 100644 --- a/tests/tests/parser/unreachable/eat_int.leo +++ b/tests/tests/parser/unreachable/eat_int.leo @@ -3,6 +3,8 @@ namespace: ParseStatement expectation: Fail */ +x.-12 + x.0_; x.0_0; From 035f763d405b62fc6f0f561242f63d371101b27e Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:07:42 -0700 Subject: [PATCH 8/9] clippy changes --- compiler/parser/src/parser/context.rs | 6 +----- compiler/passes/src/type_checking/check_statements.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/parser/src/parser/context.rs b/compiler/parser/src/parser/context.rs index 271c93704e..32ae516462 100644 --- a/compiler/parser/src/parser/context.rs +++ b/compiler/parser/src/parser/context.rs @@ -162,11 +162,7 @@ impl<'a> ParserContext<'a> { self.bump(); // Reject value if the length is over 2 and the first character is 0 if (value.len() > 1 && value.starts_with('0')) || value.contains('_') { - return Err(ParserError::tuple_index_must_be_whole_number( - &self.token.token, - self.token.span, - ) - .into()); + return Err(ParserError::tuple_index_must_be_whole_number(&self.token.token, self.token.span).into()); } Ok((PositiveNumber { value }, self.prev_token.span)) diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index b5331fac2d..8a6efa2e56 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -308,7 +308,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { (Some(Value::U64(lower_bound, _)), Some(Value::U64(upper_bound, _))) => lower_bound >= upper_bound, (Some(Value::U128(lower_bound, _)), Some(Value::U128(upper_bound, _))) => lower_bound >= upper_bound, // Note that type mismatch and non-literal errors will already be emitted by here. - _ => false + _ => false, } { self.emit_err(TypeCheckerError::loop_range_decreasing(input.stop.span())); } From 47e881f55eaf1936579508fd3039892b496b5dc9 Mon Sep 17 00:00:00 2001 From: evan-schott <53463459+evan-schott@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:11:22 -0700 Subject: [PATCH 9/9] removed inaccurate invalid-literal error --- compiler/passes/src/type_checking/check_statements.rs | 4 ---- .../compiler/statements/iteration_bound_too_large_fail.out | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/passes/src/type_checking/check_statements.rs b/compiler/passes/src/type_checking/check_statements.rs index 8a6efa2e56..7bd859bcf9 100644 --- a/compiler/passes/src/type_checking/check_statements.rs +++ b/compiler/passes/src/type_checking/check_statements.rs @@ -274,8 +274,6 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { // Note that this check is needed because the pass attempts to make progress, even though the literal may be invalid. if let Ok(value) = Value::try_from(literal) { input.start_value.replace(Some(value)); - } else { - self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span())); } } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.start.span())); @@ -288,8 +286,6 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { // Note that this check is needed because the pass attempts to make progress, even though the literal may be invalid. if let Ok(value) = Value::try_from(literal) { input.stop_value.replace(Some(value)); - } else { - self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); } } else { self.emit_err(TypeCheckerError::loop_bound_must_be_a_literal(input.stop.span())); diff --git a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out index 8a09f0aa83..966a8f720d 100644 --- a/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out +++ b/tests/expectations/compiler/statements/iteration_bound_too_large_fail.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nError [ETYC0372049]: Loop bound must be a literal.\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + - "Error [ETYC0372008]: The value 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000 is not a valid `u64`\n --> compiler-test:7:28\n |\n 7 | for i:u64 in 0u64..1000000000000000000000000000000000000000000000000000000000000000000000000000000000000u64 {\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"