Fix array type parsing, where it crashes with "IOT instruction, stack overflow"

This commit is contained in:
Gvidas Juknevičius 2024-12-21 23:07:12 +02:00
parent 8bb0e28d80
commit 6c01265f0b
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB

View File

@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use crate::tokeniser::Token; use crate::{parser::Delimiter, tokeniser::Token};
use super::{ast::{typ::Type, TokenType}, expr::parse_expr, utils, Keyword, Punctuation}; use super::{ast::{typ::Type, TokenType}, expr::parse_expr, utils, Keyword, Punctuation};
@ -15,7 +15,7 @@ pub fn parse_type(tokens: &mut Vec<Token>) -> Result<Type> {
} }
let mut typ; let mut typ;
if let Some(_) = utils::check(tokens, TokenType::Delim(super::Delimiter::SquareL)) { if let Some(_) = utils::check_consume(tokens, TokenType::Delim(super::Delimiter::SquareL)) {
let itm_typ = parse_type(tokens)?; let itm_typ = parse_type(tokens)?;
if let Some(_) = utils::check_consume(tokens, TokenType::Punct(Punctuation::Semi)) { if let Some(_) = utils::check_consume(tokens, TokenType::Punct(Punctuation::Semi)) {
let count = parse_expr(tokens, 0, false)?.unwrap(); let count = parse_expr(tokens, 0, false)?.unwrap();
@ -28,6 +28,7 @@ pub fn parse_type(tokens: &mut Vec<Token>) -> Result<Type> {
inner: Box::new(itm_typ), inner: Box::new(itm_typ),
} }
} }
_ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?;
} else { } else {
let ident = utils::check_consume_or_err(tokens, TokenType::ident(""), "a")?; let ident = utils::check_consume_or_err(tokens, TokenType::ident(""), "a")?;
typ = Type::Owned(ident.tt().unwrap_ident()); typ = Type::Owned(ident.tt().unwrap_ident());