elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.55k stars 662 forks source link

Compiler reporting success despite a change in a module which invalidates another module #1809

Open MarkFarmiloe opened 6 years ago

MarkFarmiloe commented 6 years ago

Using Elm 0.19 on Windows 10 Pro editing in VS Code, browser is Edge.

If you successfully compile a project, then make a change to a module which would cause another module not to compile, but do not change that affected module, recompiling the project reports success and running it causing uncertain results.

The example below results in nothing showing in the browser, but in my larger project I am getting undefined, which Elm promises I will not get!

snooker

To reproduce, create the index.html, Main.elm, MyModule.elm, and initial ChangedModule.elm from below, compile and run. Not too exciting.

Then change ChangedModule.elm as shown below. Recompiling reports success, but running now shows nothing.

index.html:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="main.js"></script>
</head>

<body>
    <div id="app"></div>
    <script>
        var app = Elm.Main.init({
            node: document.getElementById("app")
        });
    </script>
</body>

</html>

Main.elm:

module Main exposing (main)

import Html exposing (..)
import MyModule

view model =
    div []
        [ h1 [] [ text "First view" ]
        , MyModule.view
        ]

main =
    view ""

MyModule.elm:

module MyModule exposing (view)

import ChangedModule
import Html exposing (p, text)

view =
    ChangedModule.view "Mark"

initial ChangedModule.elm:

module ChangedModule exposing (view)

import Html exposing (Html, p, text)

view : String -> Html msg
view name =
    p [] [ text ("Your name is " ++ name) ]

final ChangedModule.elm:

module ChangedModule exposing (view)

import Html exposing (Html, p, text)

view : Bool -> String -> Html msg
view upperCase name =
    if upperCase then
        p [] [ text ("Your name is " ++ String.toUpper name) ]

    else
        p [] [ text ("Your name is " ++ name) ]
hpate-omicron commented 6 years ago

I tried this on my machine, but I get a compiler error after changing ChangedModule.elm. It did compile successfully the first time, before I changed the ChangedModule.elm, I am on a mac running 0.19.0.

elm make src/Main.elm
Detected errors in 1 module.
-- TYPE MISMATCH ---------------------------------------------- src/MyModule.elm

The 1st argument to `view` is not what I expect:

8|     ChangedModule.view "Mark"
                          ^^^^^^
This argument is a string of type:

    String

But `view` needs the 1st argument to be:

    Bool

Hint: Elm does not have “truthiness” such that ints and strings and lists are
automatically converted to booleans. Do that conversion explicitly!

Are you compiling with elm make, or something else?

MarkFarmiloe commented 6 years ago

I am using elm make from the terminal window in VS Code. Must be something to do with Windows 10 or VS Code or both. If I find out what it is, I'll report back.

hpate-omicron commented 6 years ago

I can give it a shot on a Windows machine tonight and report back as well.

rigdern commented 6 years ago

I was able to repro this using the files from @MarkFarmiloe's original post. This is the command I'm using for compiling:

elm make src/Main.elm --output="Main.js"

I am using elm 0.19.0 and macOS 10.12.6.

icidasset commented 6 years ago

I've successfully reproduced this using my own code.

Code, issue details and everything else you need can be found here: https://github.com/icidasset/elm-0.19-issue

Let me know if I missed anything. (Sidenote: I've noticed this issue in multiple projects)

absynce commented 5 years ago

@icidasset I couldn't reproduce using your project, but I think I experienced something similar after upgrading a dependency to a new major version.

What environment do you recreate this in?

I'll try to recreate my experience in an SSCCE too.

icidasset commented 5 years ago

@absynce Hey. I can still reproduce the same issue using that project of mine. Did you follow the steps/procedure in the readme?

Environment: macOS 10.14 (when I project, this was 10.13) Elm 0.19.0 using asdf version manager

Let me know if you need more info.

icidasset commented 5 years ago

Did some more testing on this (using my https://github.com/icidasset/elm-0.19-issue code) I only have the issue when the elmjutsu plugin is active.

Tested this again with the new 0.19.1 alpha and didn't have the issue. This is most likely related to the "filelock problem" which is addressed in 0.19.1.

evancz commented 5 years ago

I believe this is the same root problem as https://github.com/elm/compiler/issues/1956 which was fixed across these three commits:

Can someone confirm that the particular manifestation here is fixed by 0.19.1?