diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index de801a3..24aad38 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: - name: Build run: | rustup update stable - cargo install --path . + cargo install --debug --path . # Removed because it caused a segmentation fault and would not stop executing. Testing should be done locally. - name: Run tests run: cargo test --verbose diff --git a/Cargo.lock b/Cargo.lock index 19b8ee4..46141c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -252,8 +252,8 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "els" -version = "0.1.13-nightly.1" -source = "git+https://github.com/erg-lang/erg-language-server?branch=main#e92f3aa0bae74b9b4d7c1d4335e1a776edf307e9" +version = "0.1.13" +source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798" dependencies = [ "erg_common", "erg_compiler", @@ -273,8 +273,8 @@ dependencies = [ [[package]] name = "erg_common" -version = "0.6.1-nightly.1" -source = "git+https://github.com/erg-lang/erg?branch=main#8353e811ed20ba55a87d05e91c1a2456b03928b0" +version = "0.6.1" +source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798" dependencies = [ "backtrace-on-stack-overflow", "hermit-abi", @@ -284,8 +284,8 @@ dependencies = [ [[package]] name = "erg_compiler" -version = "0.6.1-nightly.1" -source = "git+https://github.com/erg-lang/erg?branch=main#8353e811ed20ba55a87d05e91c1a2456b03928b0" +version = "0.6.1" +source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798" dependencies = [ "erg_common", "erg_parser", @@ -293,8 +293,8 @@ dependencies = [ [[package]] name = "erg_parser" -version = "0.6.1-nightly.1" -source = "git+https://github.com/erg-lang/erg?branch=main#8353e811ed20ba55a87d05e91c1a2456b03928b0" +version = "0.6.1" +source = "git+https://github.com/erg-lang/erg?branch=main#754fb2da1374613f50da5ded05c95399dc76d798" dependencies = [ "erg_common", "unicode-xid 0.2.4", @@ -598,7 +598,7 @@ dependencies = [ [[package]] name = "py2erg" -version = "0.0.3" +version = "0.0.4" dependencies = [ "erg_common", "erg_compiler", @@ -607,7 +607,7 @@ dependencies = [ [[package]] name = "pylyzer" -version = "0.0.3" +version = "0.0.4" dependencies = [ "els", "erg_common", diff --git a/Cargo.toml b/Cargo.toml index 05c7ca9..f8e5332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,20 +15,20 @@ members = [ ] [workspace.package] -version = "0.0.3" +version = "0.0.4" authors = ["Shunsuke Shibayama "] license = "MIT OR Apache-2.0" edition = "2021" repository = "https://github.com/mtshiba/pylyzer" [workspace.dependencies] -# erg_common = "0.6.1-nightly.1" -# erg_compiler = "0.6.1-nightly.1" -# els = "0.1.13-nightly.1" +# erg_common = "0.6.1" +# erg_compiler = "0.6.1" +# els = "0.1.13" rustpython-parser = "0.1.2" -erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible"] } -erg_common = { git = "https://github.com/erg-lang/erg", branch = "main" } -els = { git = "https://github.com/erg-lang/erg-language-server", branch = "main", features = ["py_compatible"] } +erg_compiler = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible", "els"] } +erg_common = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible", "els"] } +els = { git = "https://github.com/erg-lang/erg", branch = "main", features = ["py_compatible"] } [features] debug = ["erg_compiler/debug", "erg_common/debug", "py2erg/debug"] @@ -38,7 +38,7 @@ erg_compiler = { workspace = true } erg_common = { workspace = true } els = { workspace = true } rustpython-parser = { workspace = true } -py2erg = { version = "0.0.3", path = "./crates/py2erg" } +py2erg = { version = "0.0.4", path = "./crates/py2erg" } [lib] path = "src/lib.rs" diff --git a/src/analyze.rs b/src/analyze.rs index 257baba..2f8cb79 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -3,7 +3,7 @@ use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay}; use erg_common::style::{BLUE, GREEN, RED, RESET, YELLOW}; use erg_common::traits::{Runnable, Stream}; use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact}; -use erg_compiler::context::Context; +use erg_compiler::context::ModuleContext; use erg_compiler::erg_parser::ast::AST; use erg_compiler::error::{CompileError, CompileErrors}; use erg_compiler::lower::ASTLowerer; @@ -56,10 +56,10 @@ impl Buildable for PythonAnalyzer { fn build(&mut self, code: String, mode: &str) -> Result { self.analyze(code, mode) } - fn pop_context(&mut self) -> Option { + fn pop_context(&mut self) -> Option { self.checker.pop_mod_ctx() } - fn get_context(&self) -> Option<&Context> { + fn get_context(&self) -> Option<&ModuleContext> { Some(self.checker.get_mod_ctx()) } } diff --git a/src/handle_err.rs b/src/handle_err.rs index eab7fdf..ae6a9ae 100644 --- a/src/handle_err.rs +++ b/src/handle_err.rs @@ -1,17 +1,17 @@ use erg_common::error::ErrorKind; use erg_common::log; // use erg_common::style::{remove_style, StyledString, Color}; -use erg_compiler::context::Context; +use erg_compiler::context::ModuleContext; use erg_compiler::error::{CompileError, CompileErrors}; -pub(crate) fn filter_errors(ctx: &Context, errors: CompileErrors) -> CompileErrors { +pub(crate) fn filter_errors(ctx: &ModuleContext, errors: CompileErrors) -> CompileErrors { errors .into_iter() .filter_map(|error| filter_error(ctx, error)) .collect() } -fn filter_error(_ctx: &Context, error: CompileError) -> Option { +fn filter_error(_ctx: &ModuleContext, error: CompileError) -> Option { match error.core.kind { ErrorKind::FeatureError => { log!(err "this error is ignored:"); diff --git a/tests/func.py b/tests/func.py new file mode 100644 index 0000000..2afb691 --- /dev/null +++ b/tests/func.py @@ -0,0 +1,12 @@ +def f(x: int): + for i in [1, 2, 3]: + x += i + print(x) + return x + +i: int = f(1) + +def g(x: int): + if True: + x = "a" # ERR + return x diff --git a/tests/test.rs b/tests/test.rs index 68202bd..f976da8 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -43,6 +43,11 @@ fn exec_export() { expect("tests/export.py", 0, 0); } +#[test] +fn exec_func() { + expect("tests/func.py", 0, 1); +} + #[test] fn exec_class() { expect("tests/class.py", 0, 1);