elm-lang / elm-make

A build tool for Elm projects
BSD 3-Clause "New" or "Revised" License
175 stars 45 forks source link

Add hint or warning when importing a package that has the same name as the current file #104

Open pjambet opened 8 years ago

pjambet commented 8 years ago

Hi,

I was working through the online tutorial, and when playing with the random example, I stumbled upon a weird compiler issue when trying to run the file through elm-reactor

I found multiple modules named 'Random'.

Module 'Main' is trying to import it.

Modules with that name were found in the following locations:

    directory ././Random.elm
    package elm-lang/core

I realized the file I was trying to run was named random.elm, which seems to cause a conflict when if the file contains the line import Random.

It took me a few minutes to understand what was happening (mostly because I'm an absolute beginner and don't know much about elm), but based on the excellent compiler error that elm uses, I thought that this could be something that could be improved.

It seems like if one of the import statements matches the current file, a warning (or an error) could be issued. We could also maybe make the line directory ././Random.elm a little bit more explicit to illustrate that it references the current file.

Those are just my current thoughts, there could obviously be better options.

I would be happy to work on those improvements (if they are deemed valid), but I'm not exactly sure how the compiler really works. All I found so far is this file, that seems to be involved in the process. It could be a good reason for me to start learning some haskell!

PS: Really loving elm so far, thank you so much for everything!


Using elm 0.17.0 on mac OS

process-bot commented 8 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

matthamil commented 7 years ago

I got this exact problem while working on https://guide.elm-lang.org/architecture/effects/random.html. A note should be added to this page in particular to signal to new Elm developers this potential name collision issue.

EDIT: Opened a PR to address this here https://github.com/evancz/guide.elm-lang.org/pull/67