mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-19 01:37:34 +03:00
fix more bugs, add type checking
This commit is contained in:
parent
3b62e3cc97
commit
9638a695aa
@ -189,7 +189,6 @@ impl Token {
|
||||
|
||||
let mut ended = false;
|
||||
while let Some(c) = input.next() {
|
||||
|
||||
// Check for illegal characters.
|
||||
if is_bidi_override(c) {
|
||||
return Err(ParserError::lexer_bidi_override().into());
|
||||
@ -202,7 +201,6 @@ impl Token {
|
||||
break;
|
||||
}
|
||||
string.push(c);
|
||||
|
||||
}
|
||||
|
||||
if !ended {
|
||||
@ -403,6 +401,7 @@ impl Token {
|
||||
"public" => Token::Public,
|
||||
"return" => Token::Return,
|
||||
"scalar" => Token::Scalar,
|
||||
"string" => Token::String,
|
||||
"true" => Token::True,
|
||||
"u8" => Token::U8,
|
||||
"u16" => Token::U16,
|
||||
|
@ -185,7 +185,7 @@ impl fmt::Display for Token {
|
||||
match self {
|
||||
CommentLine(s) => write!(f, "{}", s),
|
||||
CommentBlock(s) => write!(f, "{}", s),
|
||||
StaticString(s) => write!(f, "{}", s),
|
||||
StaticString(s) => write!(f, "\"{}\"", s),
|
||||
Ident(s) => write!(f, "{}", s),
|
||||
Int(s) => write!(f, "{}", s),
|
||||
True => write!(f, "true"),
|
||||
|
@ -137,7 +137,7 @@ impl<'a> TypeChecker<'a> {
|
||||
}
|
||||
ValueExpression::Group(_) => Some(self.assert_type(Type::Group, expected, value.span())),
|
||||
ValueExpression::Scalar(_, _) => Some(self.assert_type(Type::Scalar, expected, value.span())),
|
||||
ValueExpression::String(_, _) => unreachable!("String types are not reachable"),
|
||||
ValueExpression::String(_, _) => Some(self.assert_type(Type::String, expected, value.span())),
|
||||
},
|
||||
Expression::Binary(binary) => match binary.op {
|
||||
BinaryOperation::And | BinaryOperation::Or => {
|
||||
|
5
tests/compiler/char/inputs/string.in
Normal file
5
tests/compiler/char/inputs/string.in
Normal file
@ -0,0 +1,5 @@
|
||||
[main]
|
||||
hello: string = "hello";
|
||||
|
||||
[registers]
|
||||
r: string = "world";
|
11
tests/compiler/char/string.leo
Normal file
11
tests/compiler/char/string.leo
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
input_file:
|
||||
- inputs/string.in
|
||||
*/
|
||||
|
||||
function main(hello: string) -> string {
|
||||
let world: string = "world";
|
||||
return world;
|
||||
}
|
11
tests/compiler/console/log_string.leo
Normal file
11
tests/compiler/console/log_string.leo
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
input_file: inputs/dummy.in
|
||||
*/
|
||||
|
||||
function main(y: bool) -> bool {
|
||||
let hello: string = "hello world";
|
||||
console.log(hello);
|
||||
return y == true;
|
||||
}
|
8
tests/expectations/compiler/compiler/char/string.leo.out
Normal file
8
tests/expectations/compiler/compiler/char/string.leo.out
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: a7361387d9919bb2857c23ee47cc37c63f0c7cbbb7e7c92b700e2c33403fb4eb
|
||||
initial_ast: 7198afa4563739d4a07c736554459c1b59cf66c96292c67b7853b2dbc4625efe
|
||||
symbol_table: 4a29c4b5af2ad1879798454b95b7dd04ae7ecd48289c5f3e7a1e19eaf3921c3b
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'formatted static_string', got 'hello'\n --> compiler-test:5:17\n |\n 5 | console.log(hello);\n | ^^^^^"
|
@ -5,15 +5,6 @@ outputs:
|
||||
- "'\"string\"' @ 1:1-9"
|
||||
- "'\"another { } string\"' @ 1:1-21"
|
||||
- "'\"{ ] [ ; a\"' @ 1:1-12"
|
||||
- "'\"\"' @ 1:1-10"
|
||||
- "'\"\"' @ 1:1-12"
|
||||
- "'\"꾯\"' @ 1:1-11"
|
||||
- "'\"ૺ\"' @ 1:1-10"
|
||||
- "'\"¯\"' @ 1:1-9"
|
||||
- "'\"\n\"' @ 1:1-8"
|
||||
- "'\"\n\"' @ 1:1-7"
|
||||
- "'\"\u007f\"' @ 1:1-7"
|
||||
- "'\"aa \\ \" ' \n aa \t \r \u0000\"' @ 1:1-30"
|
||||
- "'\"test 😒€\"' @ 1:1-10"
|
||||
- "'\"😭😂😘\"' @ 1:1-6"
|
||||
- "'\"✋🏿\"' @ 1:1-5"
|
||||
|
@ -3,16 +3,6 @@ namespace: Token
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370023]: Expected a closed string but found `Hello world!`."
|
||||
- "Error [EPAR0370023]: Expected a closed string but found `\"`."
|
||||
- "Error [EPAR0370021]: Expected more characters to lex but found none."
|
||||
- "Error [EPAR0370022]: Expected a valid escape character but found `l`."
|
||||
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `a`."
|
||||
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `\"`."
|
||||
- "Error [EPAR0370027]: Expected a valid hex character but found `FF`."
|
||||
- "Error [EPAR0370021]: Expected more characters to lex but found none."
|
||||
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `}`."
|
||||
- "Error [EPAR0370034]: There was no opening `{` after starting an escaped unicode `6`."
|
||||
- "Error [EPAR0370029]: There was no closing `}` after a escaped unicode `af🦀\"`."
|
||||
- "Error [EPAR0370023]: Expected a closed string but found `\"`."
|
||||
- "Error [EPAR0370023]: Expected a closed string but found `\\`."
|
||||
- "Error [EPAR0370023]: Expected a closed string but found `⭇😍;`."
|
||||
- "Error [EPAR0370040]: Unicode bidi override code point encountered."
|
||||
|
@ -12,9 +12,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Error:
|
||||
string:
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
string: "{}"
|
||||
parameters:
|
||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":20,\\\"hi\\\":21}\"}"
|
||||
span:
|
||||
@ -26,11 +24,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Error:
|
||||
string:
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
string: "{}{}"
|
||||
parameters:
|
||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":22,\\\"hi\\\":23}\"}"
|
||||
- Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":25,\\\"hi\\\":26}\"}"
|
||||
@ -43,8 +37,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Error:
|
||||
string:
|
||||
- Scalar: 120
|
||||
string: x
|
||||
parameters: []
|
||||
span:
|
||||
lo: 13
|
||||
@ -55,9 +48,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Log:
|
||||
string:
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
string: "{}"
|
||||
parameters:
|
||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":19}\"}"
|
||||
span:
|
||||
@ -69,11 +60,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Log:
|
||||
string:
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
- Scalar: 123
|
||||
- Scalar: 125
|
||||
string: "{}{}"
|
||||
parameters:
|
||||
- Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":20,\\\"hi\\\":21}\"}"
|
||||
- Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":23,\\\"hi\\\":24}\"}"
|
||||
@ -86,8 +73,7 @@ outputs:
|
||||
- Console:
|
||||
function:
|
||||
Log:
|
||||
string:
|
||||
- Scalar: 120
|
||||
string: x
|
||||
parameters: []
|
||||
span:
|
||||
lo: 11
|
||||
|
@ -3,5 +3,5 @@ namespace: ParseStatement
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370040]: Unicode bidi override code point encountered."
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'formatted string', got '1'\n --> test:1:13\n |\n 1 | console.log(1);\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'formatted static_string', got '1'\n --> test:1:13\n |\n 1 | console.log(1);\n | ^"
|
||||
- "Error [EPAR0370007]: unexpected identifier: expected 'assert', 'error', 'log' -- got 'test'\n --> test:1:9\n |\n 1 | console.test();\n | ^^^^"
|
||||
|
@ -61,6 +61,20 @@ outputs:
|
||||
span:
|
||||
lo: 0
|
||||
hi: 15
|
||||
- Definition:
|
||||
declaration_type: Let
|
||||
variable_names:
|
||||
- mutable: true
|
||||
identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":4,\\\"hi\\\":5}\"}"
|
||||
span:
|
||||
lo: 4
|
||||
hi: 5
|
||||
type_: String
|
||||
value:
|
||||
Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":16,\\\"hi\\\":20}\"}"
|
||||
span:
|
||||
lo: 0
|
||||
hi: 20
|
||||
- Definition:
|
||||
declaration_type: Const
|
||||
variable_names:
|
||||
@ -120,6 +134,20 @@ outputs:
|
||||
span:
|
||||
lo: 0
|
||||
hi: 17
|
||||
- Definition:
|
||||
declaration_type: Const
|
||||
variable_names:
|
||||
- mutable: false
|
||||
identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":6,\\\"hi\\\":7}\"}"
|
||||
span:
|
||||
lo: 6
|
||||
hi: 7
|
||||
type_: String
|
||||
value:
|
||||
Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":18,\\\"hi\\\":22}\"}"
|
||||
span:
|
||||
lo: 0
|
||||
hi: 22
|
||||
- Definition:
|
||||
declaration_type: Let
|
||||
variable_names:
|
||||
|
@ -25,23 +25,23 @@ outputs:
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:10\n |\n 1 | let (x,y,,) = ();\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:6\n |\n 1 | let (,x,y) = ();\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ','\n --> test:1:8\n |\n 1 | let (x,,y) = ();\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; (2,,)] = [[0,0], [0,0]];\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'const'\n --> test:1:8\n |\n 1 | let x: const = expr;\n | ^^^^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'let'\n --> test:1:10\n |\n 1 | const x: let = expr;\n | ^^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'mut'\n --> test:1:8\n |\n 1 | let x: mut = expr;\n | ^^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; (2,,)] = [[0,0], [0,0]];\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'const'\n --> test:1:8\n |\n 1 | let x: const = expr;\n | ^^^^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'let'\n --> test:1:10\n |\n 1 | const x: let = expr;\n | ^^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got 'mut'\n --> test:1:8\n |\n 1 | let x: mut = expr;\n | ^^^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got '<eof>'\n --> test:1:1\n |\n 1 | let\n | ^^^"
|
||||
- "Error [EPAR0370005]: expected : -- got '<eof>'\n --> test:1:5\n |\n 1 | let x\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '<eof>'\n --> test:1:6\n |\n 1 | let x:\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '<eof>'\n --> test:1:6\n |\n 1 | let x:\n | ^"
|
||||
- "Error [EPAR0370005]: expected : -- got '='\n --> test:1:7\n |\n 1 | let x = (a, y]);\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got '='\n --> test:1:5\n |\n 1 | let = 1u8;\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'ident', got ';'\n --> test:1:4\n |\n 1 | let;\n | ^"
|
||||
- "Error [EPAR0370005]: expected : -- got '1'\n --> test:1:7\n |\n 1 | let x 1u8;\n | ^"
|
||||
- "Error [EPAR0370005]: expected = -- got ';'\n --> test:1:10\n |\n 1 | let x: u8;\n | ^"
|
||||
- "Error [EPAR0370005]: expected = -- got '<eof>'\n --> test:1:8\n |\n 1 | let x: u8\n | ^^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '='\n --> test:1:8\n |\n 1 | let x: = 1;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8] = 1;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; 1u8] = [1,\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '='\n --> test:1:8\n |\n 1 | let x: = 1;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8] = 1;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8;\n | ^"
|
||||
- "Error [EPAR0370005]: expected 'address', 'bool', 'field', 'group', 'scalar', 'string', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128' -- got '['\n --> test:1:8\n |\n 1 | let x: [u8; 1u8] = [1,\n | ^"
|
||||
- "Error [EPAR0370009]: unexpected string: expected 'expression', got ']'\n --> test:1:15\n |\n 1 | let dbg: u8 = ];\n | ^"
|
||||
- "Error [EPAR0370026]: Could not lex the following content: `🦀: u8 = 0;`."
|
||||
- "Error [EPAR0370035]: do not put parens around single variable names\n --> test:1:6\n |\n 1 | let (x) = ...;\n | ^\nError [EPAR0370005]: expected : -- got '='\n --> test:1:9\n |\n 1 | let (x) = ...;\n | ^"
|
||||
|
@ -9,19 +9,6 @@ expectation: Pass
|
||||
|
||||
"{ ] [ ; a"
|
||||
|
||||
"\u{FFA}"
|
||||
"\u{afafa}"
|
||||
"\u{afaf}"
|
||||
"\u{afa}"
|
||||
"\u{af}"
|
||||
"\u{a}"
|
||||
|
||||
"\x0A"
|
||||
|
||||
"\x7F"
|
||||
|
||||
"aa \\ \" \' \n aa \t \r \0"
|
||||
|
||||
"test 😒€"
|
||||
"😭😂😘"
|
||||
|
||||
|
@ -5,28 +5,10 @@ expectation: Fail
|
||||
|
||||
"Hello world!
|
||||
|
||||
"\"
|
||||
|
||||
"\
|
||||
|
||||
"\l"
|
||||
|
||||
"\uaaa"
|
||||
|
||||
"\u"
|
||||
|
||||
"\xFF"
|
||||
|
||||
"\x"
|
||||
|
||||
"\u}"
|
||||
|
||||
"\u6🦀}"
|
||||
|
||||
"\u{af🦀"
|
||||
|
||||
"\"
|
||||
|
||||
"⭇😍;
|
||||
|
||||
"2066:"
|
||||
|
||||
|
@ -9,6 +9,8 @@ let x: u16 = x+y;
|
||||
|
||||
let x: u8 = x();
|
||||
|
||||
let x: string = expr;
|
||||
|
||||
|
||||
const x: i8 = expr;
|
||||
|
||||
@ -16,6 +18,8 @@ const x: i16 = x+y;
|
||||
|
||||
const x: i8 = x();
|
||||
|
||||
const x: string = expr;
|
||||
|
||||
|
||||
let x: u32 = expr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user