This seems related to #873, #1045, et al, but I'm opening a new issue because those are over a year old, it seems a lot has been fixed since then, and this seems like an unusual case. Apologies if it's a duplicate.
Here is the smallest case I found to reproduce it. It's extremely contrived, but it stems from a real-life situation I encountered.
module Bug exposing (..)
import String
f x =
let
r _ _ = 1
m = Just x
x =
case m of
Just _ -> String.foldl r 1 "foo"
Nothing -> 0
in
x
Then using elm-repl 0.17.1:
> import Bug exposing (..)
> f 1
TypeError: Cannot read property 'ctor' of undefined
However it works fine if I simplify the function slightly in a trivial way, for instance:
f x =
let
r _ _ = 1
x =
case Just x of -- removed `m` binding
Just _ -> String.foldl r 1 "foo"
Nothing -> 0
in
x
yields
> import Bug exposing (..)
> f 1
1 : number
There are other trivial simplifications that make it work that seem to have nothing to do with removing shadowing, such as:
f x =
let
r _ _ = 1
m = Just x
x =
case m of
Just _ -> 1 -- `removed nonsensical `String.foldl` call`
Nothing -> 0
in
x
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.
FYI, type annotations have no effect
f : Int -> Int
f x =
let
r : Char -> Int -> Int
r _ _ = 1
m : Maybe Int
m = Just x
x : Int
x =
case m of
Just _ -> String.foldl r 1 "foo"
Nothing -> 0
in
x
> f 1
TypeError: Cannot read property 'ctor' of undefined
I have a TypeError: Cannot read property 'xxx' of undefined error.
I've searched my code for shadowing problems and found none.
I'll focus on fixing and/or finding a SSCCE.
I'm having this same issue, in fact. No shadowing. I'll post my results
when I get home.
On Sat, Oct 8, 2016 at 5:30 PM Mark Bolusmjak [email protected]
wrote:
I have a TypeError: Cannot read property 'xxx' of undefined error.
I've searched my code for shadowing problems and found none.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/elm-lang/elm-compiler/issues/1497#issuecomment-252449468,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAtdXV4dBZaaxqEOe47yXLn-JIW6jY4fks5qyAtWgaJpZM4KNXRI
.
According to the commit comment of https://github.com/elm-lang/elm-compiler/commit/8b484abfb313f2877403b168e4d7229863f20ba1, all three programs in the opening post here will be rejected by the compiler in version 0.18.
Yep, @jvoigtlaender is correct about that!
Most helpful comment
I'm having this same issue, in fact. No shadowing. I'll post my results
when I get home.
On Sat, Oct 8, 2016 at 5:30 PM Mark Bolusmjak [email protected]
wrote: