elm / compiler

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

Uncaught Error: The notify function has been called synchronously! #1295

Closed egaga closed 8 years ago

egaga commented 8 years ago

In browser's console log:

game.elm:2759 Uncaught TypeError: Cannot read property 'ctor' of undefined 6game.elm:1315 Uncaught Error: The notify function has been called synchronously! This can lead to frames being dropped. Definitely report this to <https://github.com/elm-lang/Elm/issues>

The translated javascript has this line referenced while (xs.ctor !== '[]' && n > 0)

I added a new action (in SimpleApp terms) to the update function:

 Action.DrawCardsToHand ->
      let (deck, player) = Domain.drawCardsToHand deck player
      in { model | player = player, deck = deck }

The problem seems to be that the arguments deck and player in the call Domain.drawCardsToHand deck player should actually be referencing model.player and model.deck. It seems that creating having a let with the needed variable (deck and player) are enough to satisfy the compiler. They are not defined globally elsewhere; though similar let constructions are defined on other action branches (case of ...).

For reference:

type alias Deck = List Card

type alias Player = {
   nick: String,
   hand: List Card,
   trade: List Card,
   side: List Card,
   fields: List Field,
   money: Int }

If this is hard-to-reproduce for others, I'll perhaps take the time to make a simple test case.

mgold commented 8 years ago

Yet another example of #873, which is common enough that I have that issue number memorized.

Thanks for reporting. You've correctly diagnosed the circular nature of the code. For now... just don't do that, m'kay?

egaga commented 8 years ago

Ah, that's good!

mgold commented 8 years ago

Would you mind closing the issue?