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 with arrays #474

Closed
ckoster22 opened this Issue Jan 6, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@ckoster22

ckoster22 commented Jan 6, 2016

Copy/paste into http://elm-lang.org/try

import Array exposing (Array)

type alias Box =
  { value : String }

convertTo2D : Array Box -> Int -> Array (Array Box)
convertTo2D boxArray numRows =
  let
    nextRow = Array.slice 0 numRows boxArray
  in
    if Array.length nextRow > 0
    then Array.push nextRow (convertTo2D (Array.slice numRows (Array.length boxArray) boxArray) numRows)
    else Array.empty

oneDimArray = Array.initialize 100 (\index -> { value = toString index })

temp = convertTo2D oneDimArray 10

This is boiled down from a larger application. The relevant error is:
"Uncaught TypeError: Cannot read property 'height' of undefined everything.js:831"

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 6, 2016

Contributor

Did you check it's not one of these existing issues about arrays?

Contributor

jvoigtlaender commented Jan 6, 2016

Did you check it's not one of these existing issues about arrays?

@ckoster22

This comment has been minimized.

Show comment
Hide comment
@ckoster22

ckoster22 Jan 6, 2016

I checked. It could possibly be this issue (https://github.com/elm-lang/core/issues/349) but it's unclear whether it's the same. None of them mention the same runtime error.

ckoster22 commented Jan 6, 2016

I checked. It could possibly be this issue (https://github.com/elm-lang/core/issues/349) but it's unclear whether it's the same. None of them mention the same runtime error.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 6, 2016

Contributor

Thanks!

Contributor

jvoigtlaender commented Jan 6, 2016

Thanks!

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Jan 6, 2016

Contributor

I've played a bit with your example. By unrolling the recursion a bit (repeatedly inlining convert2D) and trying with reduced overall size, I reduced it to this:

import Array

temp = 
  let
    n = 10
  in 
    Array.initialize (4*n) identity
    |> Array.slice n (4*n)
    |> Array.slice n (3*n)
    |> Array.slice n (2*n)
    |> Array.slice n n

This shows the same error.

And interestingly, changing n = 10 to n = 8 lets the error go away (while it remains for n = 9). Noticing that for n = 8 we have 4*n = 32, the "magic number" from #349, it might have something to do with that issue after all, or maybe share a common root problem with that one...

Contributor

jvoigtlaender commented Jan 6, 2016

I've played a bit with your example. By unrolling the recursion a bit (repeatedly inlining convert2D) and trying with reduced overall size, I reduced it to this:

import Array

temp = 
  let
    n = 10
  in 
    Array.initialize (4*n) identity
    |> Array.slice n (4*n)
    |> Array.slice n (3*n)
    |> Array.slice n (2*n)
    |> Array.slice n n

This shows the same error.

And interestingly, changing n = 10 to n = 8 lets the error go away (while it remains for n = 9). Noticing that for n = 8 we have 4*n = 32, the "magic number" from #349, it might have something to do with that issue after all, or maybe share a common root problem with that one...

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jun 25, 2016

Member

Closing in favor of #649 which will track all array issues and progress on a new implementation.

Member

evancz commented Jun 25, 2016

Closing in favor of #649 which will track all array issues and progress on a new implementation.

@wishfoundry

This comment has been minimized.

Show comment
Hide comment
@wishfoundry

wishfoundry Nov 21, 2016

I suspect this line is the culprit:

var slot = new createNode(a.height - 1, 0);

in:
https://github.com/elm-lang/core/blob/master/src/Native/Array.js#L730

createNode() generates an new node, it should not be new'ed up itself

wishfoundry commented Nov 21, 2016

I suspect this line is the culprit:

var slot = new createNode(a.height - 1, 0);

in:
https://github.com/elm-lang/core/blob/master/src/Native/Array.js#L730

createNode() generates an new node, it should not be new'ed up itself

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