Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

fix bug with import cycle detection

+19 -6
+3
CHANGELOG.md
··· 11 11 ### Language Server 12 12 13 13 ### Bug Fixes 14 + 15 + - Fixes a bug with import cycle detection when there is more than 2 imports in the cycle 16 + ([Ameen Radwan](https://github.com/Acepie))
+6 -4
compiler-core/src/build/package_loader.rs
··· 286 286 .enumerate() 287 287 .map(|(i, module)| { 288 288 // cycles are in order of reference so get next in list or loop back to first 289 - let ind = if i == modules.len() - 1 { 0 } else { i + 1 }; 290 - let next = modules.get(ind).expect("next module must exist"); 289 + let index_of_importer = if i == 0 { modules.len() - 1 } else { i - 1 }; 290 + let importing_module = modules 291 + .get(index_of_importer) 292 + .expect("importing module must exist"); 291 293 let input = dep_location_map.get(module).expect("dependency must exist"); 292 294 let location = match input { 293 295 Input::New(module) => { 294 296 let (_, location) = module 295 297 .dependencies 296 298 .iter() 297 - .find(|d| &d.0 == next) 299 + .find(|d| &d.0 == importing_module) 298 300 .expect("import must exist for there to be a cycle"); 299 301 ImportCycleLocationDetails { 300 302 location: *location, ··· 306 308 let (_, location) = cached_module 307 309 .dependencies 308 310 .iter() 309 - .find(|d| &d.0 == next) 311 + .find(|d| &d.0 == importing_module) 310 312 .expect("import must exist for there to be a cycle"); 311 313 let src = self 312 314 .io
+1
test-package-compiler/cases/import_cycle_multi/src/three.gleam
··· 1 + import one
+1 -1
test-package-compiler/cases/import_cycle_multi/src/two.gleam
··· 1 - import one 1 + import three
+8 -1
test-package-compiler/src/snapshots/test_package_compiler__generated_tests__import_cycle_multi.snap
··· 3 3 expression: "./cases/import_cycle_multi" 4 4 --- 5 5 error: Import cycle 6 + ┌─ src/three.gleam:1:1 7 + 8 + 1 │ import one 9 + │ ^ Imported here 10 + 6 11 ┌─ src/two.gleam:1:1 7 12 8 - 1 │ import one 13 + 1 │ import three 9 14 │ ^ Imported here 10 15 11 16 ┌─ src/one.gleam:1:1 ··· 16 21 The import statements for these modules form a cycle: 17 22 18 23 ┌─────┐ 24 + │ three 25 + │ ↓ 19 26 │ two 20 27 │ ↓ 21 28 │ one