From 6c01265f0baf18c1db511d77d94cff556b0e2a29 Mon Sep 17 00:00:00 2001 From: MCorange Date: Sat, 21 Dec 2024 23:07:12 +0200 Subject: [PATCH] Fix array type parsing, where it crashes with "IOT instruction, stack overflow" --- src/parser/typ.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/parser/typ.rs b/src/parser/typ.rs index 0ea0908..7617181 100644 --- a/src/parser/typ.rs +++ b/src/parser/typ.rs @@ -1,6 +1,6 @@ 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}; @@ -15,7 +15,7 @@ pub fn parse_type(tokens: &mut Vec) -> Result { } 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)?; if let Some(_) = utils::check_consume(tokens, TokenType::Punct(Punctuation::Semi)) { let count = parse_expr(tokens, 0, false)?.unwrap(); @@ -28,6 +28,7 @@ pub fn parse_type(tokens: &mut Vec) -> Result { inner: Box::new(itm_typ), } } + _ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?; } else { let ident = utils::check_consume_or_err(tokens, TokenType::ident(""), "a")?; typ = Type::Owned(ident.tt().unwrap_ident());