Skip to main content

leo_passes/check_interfaces/
mod.rs

1// Copyright (C) 2019-2026 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
17mod visitor;
18use visitor::*;
19
20use crate::{CompilerState, Pass};
21
22use leo_ast::ProgramVisitor;
23use leo_errors::Result;
24
25/// A pass to validate interface inheritance soundness.
26///
27/// Validates:
28/// 1. Interface-to-interface inheritance has no conflicting members
29/// 2. Programs implement all required interface members
30/// 3. Signature matching is exact
31pub struct CheckInterfaces;
32
33impl Pass for CheckInterfaces {
34    type Input = ();
35    type Output = ();
36
37    const NAME: &'static str = "CheckInterfaces";
38
39    fn do_pass(_: Self::Input, state: &mut CompilerState) -> Result<Self::Output> {
40        let ast = std::mem::take(&mut state.ast);
41
42        let mut visitor = CheckInterfacesVisitor::new(state);
43
44        // Explicitly handle both variants; library is a no-op for now
45        ast.visit(
46            |program| visitor.visit_program(program),
47            |_library| {
48                // no-op for library
49            },
50        );
51
52        visitor.state.handler.last_err()?;
53        visitor.state.ast = ast;
54
55        Ok(())
56    }
57}