From c8e9f083aa1bd9664b7bf18fae5490cdb4a4280a Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 12:38:02 +0100 Subject: [PATCH 01/11] testing --- src/check/state.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++ src/ty/mod.rs | 10 ++++++ 2 files changed, 87 insertions(+) diff --git a/src/check/state.rs b/src/check/state.rs index 5a6b051..dba0412 100644 --- a/src/check/state.rs +++ b/src/check/state.rs @@ -128,3 +128,80 @@ impl<'file> CheckState<'file> { todo!() } } + +#[cfg(test)] +mod tests { + use crate::{ + check::{state::CheckState, ty::tests::parse_ty}, + project::Project, + ty::{Generic, Ty}, + }; + + fn test_project() -> Project { + let mut project = Project::from( + r#"struct Foo + struct Bar + struct Baz[T] + trait Magic { + fn magic(): Self + } + trait Epic { + fn epic(): Self + } + trait Strange [T] { + fn strange(): T + } + + impl Magic for Foo + + impl Magic for Bar + impl Epic for Bar + + impl Strange[T] for Baz[T]"#, + ); + project.resolve(); + project + } + + fn test_state<'a>(project: &'a Project) -> CheckState<'a> { + let file_data = project.get_file(0).unwrap(); + CheckState::from_file(file_data, project) + } + + #[test] + fn variables() { + let project = test_project(); + let mut state = test_state(&project); + state.enter_scope(); + state.insert_variable("foo".to_string(), parse_ty(&project, "Foo")); + assert_eq!( + *state.get_variable("foo").unwrap(), + parse_ty(&project, "Foo") + ); + state.exit_scope(); + assert!(state.get_variable("foo").is_none()); + } + + #[test] + fn generics() { + let project = test_project(); + let mut state = test_state(&project); + state.enter_scope(); + state.insert_generic( + "T".to_string(), + Generic { + name: "T".to_string(), + ..Default::default() + }, + ); + assert_eq!( + *state.get_generic("T").unwrap(), + Generic { + name: "T".to_string(), + ..Default::default() + } + ); + state.exit_scope(); + assert!(state.get_generic("T").is_none()); + } +} diff --git a/src/ty/mod.rs b/src/ty/mod.rs index 53a876b..5936a66 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -16,6 +16,16 @@ pub struct Generic { pub super_: Box, } +impl Default for Generic { + fn default() -> Self { + Self { + name: "".to_string(), + variance: Variance::Invariant, + super_: Box::new(Ty::Any), + } + } +} + impl Generic { pub fn get_name(&self, project: &Project) -> String { format!( From 4d51b6a43dc9b280c26d7f936894972a63c3b5ee Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 13:24:10 +0100 Subject: [PATCH 02/11] update lint permissions --- .github/workflows/lint.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 165e6c3..772dcb8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,3 +1,9 @@ +permissions: + contents: write + issues: write + checks: write + pull-requests: write + on: pull_request: push: From 649eccc1aee8505a6a6023e71efda7c9b4b94825 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 13:43:04 +0100 Subject: [PATCH 03/11] Updating clippy warnings --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 772dcb8..7b05804 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -56,5 +56,5 @@ jobs: - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features + args: -D clippy::correctness -D clippy::complexity -D clippy::pedantic -D clippy::nursery -D clippy::perf -D clippy::cargo name: Clippy Output From 798b79e220956208fb1335c01e4a70b753175159 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 13:52:58 +0100 Subject: [PATCH 04/11] switched s --- .github/workflows/lint.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7b05804..3c1e011 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -47,14 +47,10 @@ jobs: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable with: - toolchain: stable components: clippy - override: true - - uses: actions-rs/clippy-check@v1 + - uses: auguwu/clippy-action@1.4.0 with: - token: ${{ secrets.GITHUB_TOKEN }} - args: -D clippy::correctness -D clippy::complexity -D clippy::pedantic -D clippy::nursery -D clippy::perf -D clippy::cargo - name: Clippy Output + token: ${{secrets.GITHUB_TOKEN}} From 8c0205b3369f02f0b644bf572a69e3556d2ed0fd Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 14:24:53 +0100 Subject: [PATCH 05/11] Updated clippy args --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3c1e011..f0346b0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -54,3 +54,4 @@ jobs: - uses: auguwu/clippy-action@1.4.0 with: token: ${{secrets.GITHUB_TOKEN}} + args: -D clippy::correctness -D clippy::complexity -D clippy::pedantic -D clippy::nursery -D clippy::perf -D clippy::cargo From f95deb299121748e64d52954cfc3cf13984f6685 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 14:49:12 +0100 Subject: [PATCH 06/11] include tests in clippy lints --- .github/workflows/lint.yml | 2 +- Cargo.toml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f0346b0..e180396 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -54,4 +54,4 @@ jobs: - uses: auguwu/clippy-action@1.4.0 with: token: ${{secrets.GITHUB_TOKEN}} - args: -D clippy::correctness -D clippy::complexity -D clippy::pedantic -D clippy::nursery -D clippy::perf -D clippy::cargo + args: --tests diff --git a/Cargo.toml b/Cargo.toml index 36d046f..1fc53d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,9 @@ name = "another-giblang-impl" version = "0.1.0" edition = "2021" +description = "Another implementation of the Giblang programming language" +repository = "https:://github.com/mnbjhu/another-giblang-impl" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,3 +14,5 @@ clap = { version = "4.5.3", features = ["derive"] } chumsky = "1.0.0-alpha.7" ptree = "0.4.0" glob = "0.3.1" + +[lints.clippy] From 56ae8e1e04b6caf5c941a0fd24fd03b60190092b Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 14:51:24 +0100 Subject: [PATCH 07/11] fix --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e180396..7fada88 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -54,4 +54,4 @@ jobs: - uses: auguwu/clippy-action@1.4.0 with: token: ${{secrets.GITHUB_TOKEN}} - args: --tests + args: --cfg test From 6dee7ad426164f60b56ae26ba55700fba4ca3de5 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 15:09:15 +0100 Subject: [PATCH 08/11] deny warnings --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7fada88..f8f223a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -54,4 +54,4 @@ jobs: - uses: auguwu/clippy-action@1.4.0 with: token: ${{secrets.GITHUB_TOKEN}} - args: --cfg test + args: --cfg test -D warnings From 510e80ec48891cf68123b8024f447fe198a82f1c Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 15:14:11 +0100 Subject: [PATCH 09/11] Revert to previous clippy plugin --- .github/workflows/lint.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f8f223a..32a49dd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -47,11 +47,27 @@ jobs: name: Clippy runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 with: + toolchain: stable components: clippy - - uses: auguwu/clippy-action@1.4.0 + override: true + - uses: actions-rs/clippy-check@v1 with: - token: ${{secrets.GITHUB_TOKEN}} - args: --cfg test -D warnings + token: ${{ secrets.GITHUB_TOKEN }} + args: --tests + name: Clippy Output + + # clippy: + # name: Clippy + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - uses: dtolnay/rust-toolchain@stable + # with: + # components: clippy + # - uses: auguwu/clippy-action@1.4.0 + # with: + # token: ${{secrets.GITHUB_TOKEN}} + # args: --cfg test -D warnings From 69d4585d6381378fc18f2a7438f9596854c65f26 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 15:17:01 +0100 Subject: [PATCH 10/11] deny warnings --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 32a49dd..1e5b557 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -56,7 +56,7 @@ jobs: - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --tests + args: --tests -- -D warnings name: Clippy Output # clippy: From b6958b85d4806eb59f1d79663a2d9ef15b3ba39f Mon Sep 17 00:00:00 2001 From: james Date: Tue, 6 Aug 2024 15:22:04 +0100 Subject: [PATCH 11/11] Fixed warnings --- src/check/state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/check/state.rs b/src/check/state.rs index dba0412..2b629e3 100644 --- a/src/check/state.rs +++ b/src/check/state.rs @@ -134,7 +134,7 @@ mod tests { use crate::{ check::{state::CheckState, ty::tests::parse_ty}, project::Project, - ty::{Generic, Ty}, + ty::Generic, }; fn test_project() -> Project { @@ -163,7 +163,7 @@ mod tests { project } - fn test_state<'a>(project: &'a Project) -> CheckState<'a> { + fn test_state(project: &Project) -> CheckState { let file_data = project.get_file(0).unwrap(); CheckState::from_file(file_data, project) }