array type inference bugs

This commit is contained in:
gluax 2021-06-23 07:08:32 -07:00
parent 214c5b21c9
commit 068958a2f4
5 changed files with 285 additions and 13 deletions

View File

@ -66,10 +66,12 @@ impl<'a> ExpressionNode<'a> for ArrayInlineExpression<'a> {
}
fn get_type(&self) -> Option<Type<'a>> {
Some(Type::Array(
Box::new(self.elements.first()?.0.get().get_type()?),
self.expanded_length(),
))
let first = self.elements.first()?;
let inner_type = match first.0.get().get_type()? {
Type::Array(inner, _) if first.1 => *inner,
_ => first.0.get().get_type()?,
};
Some(Type::Array(Box::new(inner_type), self.expanded_length()))
}
fn is_mut_ref(&self) -> bool {

View File

@ -1327,11 +1327,278 @@
"content": " const o = \"Hello, World!\";"
}
}
},
{
"Definition": {
"declaration_type": "Const",
"variable_names": [
{
"mutable": false,
"identifier": "{\"name\":\"p\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const p = [...[1u8], ...[2u8]];\\\"}\"}",
"span": {
"line_start": 25,
"line_stop": 25,
"col_start": 9,
"col_stop": 10,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
}
],
"type_": {
"Array": [
{
"IntegerType": "U8"
},
[
{
"value": "2"
}
]
]
},
"value": {
"ArrayInline": {
"elements": [
{
"Spread": {
"ArrayInline": {
"elements": [
{
"Expression": {
"Value": {
"Integer": [
"U8",
"1",
{
"line_start": 25,
"line_stop": 25,
"col_start": 18,
"col_stop": 21,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
]
}
}
}
],
"span": {
"line_start": 25,
"line_stop": 25,
"col_start": 17,
"col_stop": 22,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
}
}
},
{
"Spread": {
"ArrayInline": {
"elements": [
{
"Expression": {
"Value": {
"Integer": [
"U8",
"2",
{
"line_start": 25,
"line_stop": 25,
"col_start": 28,
"col_stop": 31,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
]
}
}
}
],
"span": {
"line_start": 25,
"line_stop": 25,
"col_start": 27,
"col_stop": 32,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
}
}
}
],
"span": {
"line_start": 25,
"line_stop": 25,
"col_start": 13,
"col_stop": 33,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
}
},
"span": {
"line_start": 25,
"line_stop": 25,
"col_start": 3,
"col_stop": 33,
"path": "",
"content": " const p = [...[1u8], ...[2u8]];"
}
}
},
{
"Definition": {
"declaration_type": "Const",
"variable_names": [
{
"mutable": false,
"identifier": "{\"name\":\"q\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const q = [...p, 3u8] == [1u8, 2u8, 3u8];\\\"}\"}",
"span": {
"line_start": 26,
"line_stop": 26,
"col_start": 9,
"col_stop": 10,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
}
],
"type_": "Boolean",
"value": {
"Binary": {
"left": {
"ArrayInline": {
"elements": [
{
"Spread": {
"Identifier": "{\"name\":\"p\",\"span\":\"{\\\"line_start\\\":26,\\\"line_stop\\\":26,\\\"col_start\\\":17,\\\"col_stop\\\":18,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const q = [...p, 3u8] == [1u8, 2u8, 3u8];\\\"}\"}"
}
},
{
"Expression": {
"Value": {
"Integer": [
"U8",
"3",
{
"line_start": 26,
"line_stop": 26,
"col_start": 20,
"col_stop": 23,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
]
}
}
}
],
"span": {
"line_start": 26,
"line_stop": 26,
"col_start": 13,
"col_stop": 24,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
}
},
"right": {
"ArrayInline": {
"elements": [
{
"Expression": {
"Value": {
"Integer": [
"U8",
"1",
{
"line_start": 26,
"line_stop": 26,
"col_start": 29,
"col_stop": 32,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
]
}
}
},
{
"Expression": {
"Value": {
"Integer": [
"U8",
"2",
{
"line_start": 26,
"line_stop": 26,
"col_start": 34,
"col_stop": 37,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
]
}
}
},
{
"Expression": {
"Value": {
"Integer": [
"U8",
"3",
{
"line_start": 26,
"line_stop": 26,
"col_start": 39,
"col_stop": 42,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
]
}
}
}
],
"span": {
"line_start": 26,
"line_stop": 26,
"col_start": 28,
"col_stop": 43,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
}
},
"op": "Eq",
"span": {
"line_start": 26,
"line_stop": 26,
"col_start": 13,
"col_stop": 43,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
}
},
"span": {
"line_start": 26,
"line_stop": 26,
"col_start": 3,
"col_stop": 43,
"path": "",
"content": " const q = [...p, 3u8] == [1u8, 2u8, 3u8];"
}
}
}
],
"span": {
"line_start": 9,
"line_stop": 25,
"line_stop": 27,
"col_start": 17,
"col_stop": 2,
"path": "",
@ -1340,11 +1607,11 @@
},
"span": {
"line_start": 9,
"line_stop": 25,
"line_stop": 27,
"col_start": 1,
"col_stop": 2,
"path": "",
"content": "function main() {\n...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
"content": "function main() {\n...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
}
}
}

View File

@ -22,4 +22,6 @@ function main() {
const m = Foo {};
const n = 'a';
const o = "Hello, World!";
const p = [...[1u8], ...[2u8]];
const q = [...p, 3u8] == [1u8, 2u8, 3u8];
}

View File

@ -8,6 +8,7 @@ input_file: input/three_ones.in
function main(a: [u8; 3]) -> bool {
const b = [1u8, 1u8];
const c = [1u8, ...b];
const d = [...b, 1u8];
return a == c;
return a == c && d == a;
}

View File

@ -4,11 +4,11 @@ expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 47
num_constraints: 47
at: 9034e7c6c2ae58e279196614600093d655bcdad8237302b84a66e63ec1c2f00e
bt: f23a0442b41c8901611d5f1a9a8493a0cb03c68e183a81a1b88c5a6600fa7420
ct: ad66abc1bf940dbc76573c0a516ebf633c1411f9997101d86ded0faff025d52c
num_private_variables: 71
num_constraints: 71
at: a08e2e54701e419ba564483a59fb3f6cc30614b8a7c903f9ff6f4b85e63da5c6
bt: 65113b6e5dc0f7d88f04b7e60a519801a313d2e9d4129db502ccef0dfdb14988
ct: 7a28ca50094ed4577eef8066cf1a814affa63139e6cc3d7ccf8d65c69499de60
output:
- input_file: input/three_ones.in
output: