gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.97k stars 750 forks source link

Caching problem when updating dependencies #3772

Open joshi-monster opened 1 week ago

joshi-monster commented 1 week ago

I found a reproduction for a build directory caching problem using this repo.

Inside of the repository, running these commands:

rm -fr build
# last "good" commit
git checkout e2ceac56ba5afa9b7a27d8a08e70e2cee619d15d; gleam build
# update all dependencies
git checkout 18bda7afecb40f5425ed47c79722cd7ccbdefeba; gleam build
# fix some of the errors (nakai), but not all of them (mist/wisp)
git checkout ecc3a5f92a46312b429e3736dd8cb370f5c744ae; gleam build

produces:

removed directory 'build'
Previous HEAD position was ecc3a5f 🐛 fix: comply with latest nakai api
HEAD is now at e2ceac5 ✨ feature: delete files
   [...gleam build output stripped...]
   Compiled in 120.14s
Previous HEAD position was e2ceac5 ✨ feature: delete files
HEAD is now at 18bda7a 📦 deps: bump everything
Downloading packages
 Downloaded 18 packages in 0.21s
 [...gleam build output stripped...]
error: Incorrect arity
   ┌─ /home/arkan/Projects/probe/june/src/june/pages.gleam:29:9
   │
29 │         attr.crossorigin(),
   │         ^^^^^^^^^^^^^^^^^^ Expected 1 argument, got 0

Previous HEAD position was 18bda7a 📦 deps: bump everything
HEAD is now at ecc3a5f 🐛 fix: comply with latest nakai api
  Compiling june
error: Type mismatch
   ┌─ /home/arkan/Projects/probe/june/src/june/router.gleam:24:29
   │
24 │   use req <- web.middleware(req)
   │                             ^^^

Expected type:

    Request(Connection)

Found type:

    Request(wisp/internal.Connection)

error: Type mismatch
   ┌─ /home/arkan/Projects/probe/june/src/june/router.gleam:27:23
   │
27 │     [] -> handle_root(req)
   │                       ^^^

Expected type:

    Request(Connection)

Found type:

    Request(wisp.Connection)

error: Type mismatch
   ┌─ /home/arkan/Projects/probe/june/src/june/router.gleam:28:31
   │
28 │     _ -> handle_retrieve_file(req)
   │                               ^^^

Expected type:

    Request(Connection)

Found type:

    Request(wisp.Connection)

removing the build directory again and rebuilding reveals another type error and gets rid of the errors above:

error: Unknown module value
   ┌─ /home/arkan/Projects/probe/june/src/june.gleam:17:9
   │
17 │     wisp.mist_handler(router.handle_request, token)
   │         ^^^^^^^^^^^^^

The module `wisp` does not have a `mist_handler` value.

Just guessing here, but I think it has to do with the fact that type checking stops after finding that first nakai-related error, but the compiler then assumes this was the only dependency-related problem.

Gleam 1.5.1 ~ :purple_heart:

lpil commented 1 week ago

Thank you for figuring out how to replicate this one!

joshi-monster commented 3 days ago

I found a better one that starts from a fresh project!! It's a little bit different, but it looks like it's the same problem to me.

Make a new gleam project with the following main module:

import gleam/io
import gleam/set

pub fn main() {
  let s = set.from_list([1, 1, 2, 3])
  use x <- set.each(s) // available only on the latest version
  io.debug(x)
}

then run these commands:

gleam run # to have a build/ cache
 # required because you can't `add` a specific version if it's already locked
gleam remove gleam_stdlib
gleam add gleam_stdlib@0.39.0

# first gleam run: shows the compile error
gleam run
# second gleam run: tries to run anyways
gleam run

the second gleam run runs the program, but crashes with

runtime error: Erlang error

A function was called but it did not exist.

stacktrace:
  gleam/set.each unknown source

~ :purple_heart:

lpil commented 1 day ago

Hero! Thank you!