leo_passes/const_propagation/type_.rs
1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::ConstPropagationVisitor;
18
19use leo_ast::{ExpressionReconstructor, Node, TypeReconstructor};
20
21impl TypeReconstructor for ConstPropagationVisitor<'_> {
22 fn reconstruct_array_type(&mut self, input: leo_ast::ArrayType) -> (leo_ast::Type, Self::AdditionalOutput) {
23 let (length, opt_value) = self.reconstruct_expression(*input.length);
24
25 // If we can't evaluate this array length, keep track of it for error reporting later
26 if opt_value.is_none() {
27 self.array_length_not_evaluated = Some(length.span());
28 }
29
30 (
31 leo_ast::Type::Array(leo_ast::ArrayType {
32 element_type: Box::new(self.reconstruct_type(*input.element_type).0),
33 length: Box::new(length),
34 }),
35 Default::default(),
36 )
37 }
38}