diff --git a/CHANGELOG.md b/CHANGELOG.md index db85a4dfd..89ef9a7e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,10 @@ ### Language Server ### Bug Fixes + +## v1.3.1 - 2024-07-10 + +### Bug Fixes + +- Fixes a bug with import cycle detection when there is more than 2 imports in the cycle + ([Ameen Radwan](https://github.com/Acepie)) diff --git a/Cargo.lock b/Cargo.lock index 3e21aa2d2..830f41639 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -286,9 +286,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "camino" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +checksum = "e0ec6b951b160caa93cc0c7b209e5a3bff7aae9062213451ac99493cd844c239" dependencies = [ "serde", ] @@ -1520,9 +1520,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", "indexmap 2.2.6", @@ -1746,9 +1746,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", diff --git a/compiler-core/src/build/package_loader.rs b/compiler-core/src/build/package_loader.rs index 6bb6b1e05..dbdb5092d 100644 --- a/compiler-core/src/build/package_loader.rs +++ b/compiler-core/src/build/package_loader.rs @@ -286,15 +286,17 @@ where .enumerate() .map(|(i, module)| { // cycles are in order of reference so get next in list or loop back to first - let ind = if i == modules.len() - 1 { 0 } else { i + 1 }; - let next = modules.get(ind).expect("next module must exist"); + let index_of_imported = if i == 0 { modules.len() - 1 } else { i - 1 }; + let imported_module = modules + .get(index_of_imported) + .expect("importing module must exist"); let input = dep_location_map.get(module).expect("dependency must exist"); let location = match input { Input::New(module) => { let (_, location) = module .dependencies .iter() - .find(|d| &d.0 == next) + .find(|d| &d.0 == imported_module) .expect("import must exist for there to be a cycle"); ImportCycleLocationDetails { location: *location, @@ -306,7 +308,7 @@ where let (_, location) = cached_module .dependencies .iter() - .find(|d| &d.0 == next) + .find(|d| &d.0 == imported_module) .expect("import must exist for there to be a cycle"); let src = self .io diff --git a/nix/glistix.nix b/nix/glistix.nix index 1a0b2a1d5..42b262a31 100644 --- a/nix/glistix.nix +++ b/nix/glistix.nix @@ -39,7 +39,7 @@ rustPlatform.buildRustPackage { buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin [ Security SystemConfiguration ]; - cargoHash = "sha256-I5oYfY4zcuhDe5WsbWzso+CFafqymOYEmxD4DmV/NOo="; + cargoHash = "sha256-rifIMUYfnmVCaS+OaQ3POEaZj00cU3Biaz2ZKj2eFL4="; meta = with lib; { description = "A fork of the Gleam compiler with a Nix backend"; diff --git a/test-package-compiler/cases/import_cycle_multi/src/three.gleam b/test-package-compiler/cases/import_cycle_multi/src/three.gleam new file mode 100644 index 000000000..4481f61e4 --- /dev/null +++ b/test-package-compiler/cases/import_cycle_multi/src/three.gleam @@ -0,0 +1 @@ +import one diff --git a/test-package-compiler/cases/import_cycle_multi/src/two.gleam b/test-package-compiler/cases/import_cycle_multi/src/two.gleam index 4481f61e4..9dbb4ddc0 100644 --- a/test-package-compiler/cases/import_cycle_multi/src/two.gleam +++ b/test-package-compiler/cases/import_cycle_multi/src/two.gleam @@ -1 +1 @@ -import one +import three diff --git a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_cycle_multi.snap b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_cycle_multi.snap index 19aa07e64..7b2c1b8dc 100644 --- a/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_cycle_multi.snap +++ b/test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_cycle_multi.snap @@ -3,9 +3,14 @@ source: test-package-compiler/src/generated_tests.rs expression: "./cases/import_cycle_multi" --- error: Import cycle - ┌─ src/two.gleam:1:1 + ┌─ src/three.gleam:1:1 │ 1 │ import one + │ ^ Imported here + │ + ┌─ src/two.gleam:1:1 + │ +1 │ import three │ ^ Imported here │ ┌─ src/one.gleam:1:1 @@ -16,6 +21,8 @@ error: Import cycle The import statements for these modules form a cycle: ┌─────┐ + │ three + │ ↓ │ two │ ↓ │ one