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

runtime error in Json decoding #704

Closed
goertzenator opened this Issue Aug 30, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@goertzenator

goertzenator commented Aug 30, 2016

I have a Json decoder that creates a JS runtime error when executed. Note that decodeOffsets is factored out as a separate function:

decodeEeprom : Json.Decoder Eeprom
decodeEeprom =
    let
        createEeprom offsets subchannel_config channel_desc =
            { offsets = offsets,
              subchannel_config = subchannel_config,
              channel_desc = channel_desc
            }
        decodeOffsets           = "offsets" := decodeOffsets
        decodeSubchannel_config = "subchannel_config" := Json.list Json.int
        decodeChannel_desc      = "channel_desc" := Json.list Json.string
    in
        Json.object3 createEeprom decodeOffsets decodeSubchannel_config decodeChannel_desc

decodeOffsets = Json.list Json.float

The incorrect JS that is generated is...

var _user$project$Eeprom$decodeEeprom = function () {
    var decodeChannel_desc = A2(
        _elm_lang$core$Json_Decode_ops[':='],
        'channel_desc',
        _elm_lang$core$Json_Decode$list(_elm_lang$core$Json_Decode$string));
    var decodeSubchannel_config = A2(
        _elm_lang$core$Json_Decode_ops[':='],
        'subchannel_config',
        _elm_lang$core$Json_Decode$list(_elm_lang$core$Json_Decode$int));
    var decodeOffsets = A2(_elm_lang$core$Json_Decode_ops[':='], 'offsets', decodeOffsets); //<- decodeOffsets param is undefined!
    var createEeprom = F3(
        function (offsets, subchannel_config, channel_desc) {
            return {offsets: offsets, subchannel_config: subchannel_config, channel_desc: channel_desc};
        });
    return A4(_elm_lang$core$Json_Decode$object3, createEeprom, decodeOffsets, decodeSubchannel_config, decodeChannel_desc);
}();

In the above the decodeOffsets parameter to decodeOffsets = A2(... I assume should actually be referring to this function:

var _user$project$Eeprom$decodeOffsets = _elm_lang$core$Json_Decode$list(_elm_lang$core$Json_Decode$float);

But it doesn't, and it eventually crashes. :(

This is on elm-lang/core-4.0.5.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 30, 2016

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.

process-bot commented Aug 30, 2016

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.

@goertzenator

This comment has been minimized.

Show comment
Hide comment
@goertzenator

goertzenator Aug 30, 2016

I've boiled this down to a much simpler example, and it may just be my misunderstanding of the language. In let y = y I assume this to mean "Create a local variable named y with the same value as the module-scoped y." But something else is clearly happening and instead of seeing the output "123" I see "<internal structure>".

I'm leaving the Json case above in place because it manifests in a more serious javascript crash.

import Html exposing (text)

main =
  text (toString x)

x : Int
x =
    let
        --y = 123  -- this outputs "123"
        y = y     -- this outputs "<internal structure>"
    in
        y

y = 123  -- not needed in "y = y" case

goertzenator commented Aug 30, 2016

I've boiled this down to a much simpler example, and it may just be my misunderstanding of the language. In let y = y I assume this to mean "Create a local variable named y with the same value as the module-scoped y." But something else is clearly happening and instead of seeing the output "123" I see "<internal structure>".

I'm leaving the Json case above in place because it manifests in a more serious javascript crash.

import Html exposing (text)

main =
  text (toString x)

x : Int
x =
    let
        --y = 123  -- this outputs "123"
        y = y     -- this outputs "<internal structure>"
    in
        y

y = 123  -- not needed in "y = y" case
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 30, 2016

Member

Duplicate of elm/compiler#873

Member

evancz commented Aug 30, 2016

Duplicate of elm/compiler#873

@evancz evancz closed this Aug 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment