Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition order problem with unboxed types in --optimize #1836

Closed
Carlsson87 opened this issue Nov 6, 2018 · 3 comments
Closed

Definition order problem with unboxed types in --optimize #1836

Carlsson87 opened this issue Nov 6, 2018 · 3 comments

Comments

@Carlsson87
Copy link

The following SSCCE works fine when compiled without the --optimize flag, but causes a runtime exception when compiled with the --optimize flag.

module Main exposing (main)

import Browser
import Browser.Dom
import Html
import Task


main : Program () () ()
main =
    Browser.element
        { init = \_ -> ( (), Task.attempt (always ()) (Browser.Dom.focus "an-id") )
        , view = \_ -> Html.text ""
        , update = \_ _ -> ( (), Cmd.none )
        , subscriptions = \_ -> Sub.none
        }
  • Elm 0.19
  • Google Chrome 70.0.3538.77
  • macOS Mojave 10.14

The problematic line in the compiled output is:

var elm$browser$Browser$Dom$NotFound = elm$core$Basics$identity;

which appears above/before the definition of elm$core$Basics$identity, which causes elm$browser$Browser$Dom$NotFound to be undefined.

@evancz evancz added the gen label Nov 19, 2018
@evancz evancz changed the title Order of functions in optimized build causes a function to be undefined Definition order problem with unboxed types in --optimize Nov 19, 2018
@evancz evancz added the bug label Nov 19, 2018
@Checksum
Copy link

Checksum commented Feb 6, 2019

Just ran into this as well, but with elm$browser$Browser$Dom$NotFound. Can this be safely ignored till it's fixed, or should I be turning off --optimize?

@cedricss
Copy link

cedricss commented Feb 12, 2019

I just run into the same error with elm 0.19 and the --optimize flag:

image

Here is my minimal test case with a Browser.application and Browser.Dom.getElement, similar to the one posted above:

module Main exposing (main)

import Browser
import Browser.Dom
import Browser.Navigation as Nav
import Html exposing (Html)
import Task exposing (attempt)
import Url exposing (Url)


type alias Flags =
    {}


type Msg
    = NoOp


main : Program Flags () Msg
main =
    Browser.application
        { init = init
        , onUrlRequest = \_ -> NoOp
        , onUrlChange = \_ -> NoOp
        , view = \_ -> { title = "", body = [] }
        , update = \_ _ -> ( (), Cmd.none )
        , subscriptions = \_ -> Sub.none
        }


init : Flags -> Url -> Nav.Key -> ( (), Cmd Msg )
init flags url key =
    ( ()
    , Browser.Dom.getElement "id"
        |> Task.attempt (always NoOp)
    )

Related issue: elm/browser#63

@evancz evancz closed this as completed in a798228 Feb 13, 2019
@evancz
Copy link
Member

evancz commented Feb 13, 2019

There is a fix for this, but just to set time expectations, there is quite a bit of work left before a 0.19.1 release is possible. In particular, I found some performance issues caused by laziness that require some larger changes to address reliably. Anyway, thank you for the report!

rlefevre added a commit to dmy/elm-doc-preview that referenced this issue Mar 16, 2019
Work-around for the following elm compiler bug:
elm/compiler#1836

We put the `identity` function at the top the generated js file.
This can be removed once next Elm version is released and used.
rlefevre added a commit to dmy/elm-doc-preview that referenced this issue Mar 16, 2019
Work-around for the following elm compiler bug:
elm/compiler#1836

We put the `identity` function at the top the generated js file.
This can be removed once next Elm version is released and used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants