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

Array.length producing this error: TypeError: Cannot read property 'height' of undefined #549

Closed
rebelwarrior opened this Issue Apr 4, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@rebelwarrior
Contributor

rebelwarrior commented Apr 4, 2016

Hi, I got an unusual error after compilation:

Successfully compiled SublistTests.elm
Running tests...
Cannot read property 'height' of undefined
[stdin]:415
                throw error;
                ^

TypeError: Cannot read property 'height' of undefined
    at length ([stdin]:7895:12)
    at sliceRight ([stdin]:7499:14)
    at sliceRight ([stdin]:7514:16)
    at Function.slice [as func] ([stdin]:7494:26)
    at A3 ([stdin]:867:10)
    at Function.func ([stdin]:9114:27)
    at A3 ([stdin]:867:10)
    at Function.func ([stdin]:9132:39)
    at A3 ([stdin]:867:10)
    at Function.func ([stdin]:9140:14)

This is the offending code:

ifArrayFits : Array.Array a -> Array.Array a -> Int -> Bool
ifArrayFits array1 array2 indexOf2 =
  let
    indexEnd = (Array.length array1) + indexOf2
  in
    (array1 == (Array.slice indexOf2 indexEnd array2))

This is from exercism.io here is the link:
exercism.io/rebelwarrior/elm/sublist
Version 0.16 of Elm.
It could be related to the way it is tested. I tried all the commands in this function in the repl and all worked fine. However, if I simply returned True or False from the function and commented out the code the error disappeared.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@rebelwarrior

This comment has been minimized.

Show comment
Hide comment
@rebelwarrior

rebelwarrior Apr 5, 2016

Contributor

Definitely not #349.
If I hard code indexEnd to 32 33 or even 133 I get no error.
It's not the slice alone it's the array + length that's producing the error.

Sent from my mobile.

On Apr 5, 2016, at 1:20 AM, Janis Voigtländer notifications@github.com wrote:

Probably the same as #349 and/or #474?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

Contributor

rebelwarrior commented Apr 5, 2016

Definitely not #349.
If I hard code indexEnd to 32 33 or even 133 I get no error.
It's not the slice alone it's the array + length that's producing the error.

Sent from my mobile.

On Apr 5, 2016, at 1:20 AM, Janis Voigtländer notifications@github.com wrote:

Probably the same as #349 and/or #474?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Apr 5, 2016

Contributor

If I hard code indexEnd to 32 33 or even 133 I get no error.

Doesn't mean https://github.com/elm-lang/core/pull/399 won't fix this.

Contributor

jvoigtlaender commented Apr 5, 2016

If I hard code indexEnd to 32 33 or even 133 I get no error.

Doesn't mean https://github.com/elm-lang/core/pull/399 won't fix this.

@rebelwarrior

This comment has been minimized.

Show comment
Hide comment
@rebelwarrior

rebelwarrior Apr 5, 2016

Contributor

Here is another weird thing I tried it on try elm and reproduced the error with this code. So it seems to be an intermittent issue with very large Arrays. Note that changing the end number of the first array up or down one digit makes the error go away and so does making it larger say by adding a zero.

module Sublist (..) where

import Array
import Graphics.Element exposing (..)
import Debug exposing (..)

sublist : List comparable -> List comparable -> String
sublist list1 list2 =
  let
    size1 = List.length list1
    size2 = List.length list2
  in
    if list1 == list2 then
      "Equal"
    else if List.isEmpty list1 && not (List.isEmpty list2) then
      "Sublist"
    else if List.isEmpty list2 && not (List.isEmpty list1) then
      "Superlist"
    else if size1 <= size2 && isSublistOf list1 list2 then
      "Sublist"
    else if size2 <= size1 && isSublistOf list2 list1 then
      "Superlist"
    else
      "Unequal"

isSublistOf list1 list2 =
  let
    array1 = Array.fromList list1
    array2 = Array.fromList list2
  in
    -- check recursively if array2 indexes match first element of array1
    -- if so check if it fits
    checkArrayEl_r array1 array2 0

checkArrayEl_r : Array.Array a -> Array.Array a -> Int -> Bool
checkArrayEl_r array1 array2 indexOf2 =
  case (Array.get indexOf2 array2) of
    Nothing -> False
    Just el2 ->
      case (Array.get 0 array1) of
        Nothing -> False
        Just el1 ->
          if el1 /= el2 then
            checkArrayEl_r array1 array2 (indexOf2 + 1)
          else
            ifArrayFits array1 array2 indexOf2

ifArrayFits : Array.Array a -> Array.Array a -> Int -> Bool
ifArrayFits array1 array2 indexOf2 =
  -- Code below is producing an error and it should not...
  -- TypeError: Cannot read property 'height' of undefined
  let
    indexEnd = (Array.length array1)
    x = log ((toString indexOf2) ++ "---------**------")
    -- indexEnd = 133
  in
    (array1 == (Array.slice indexOf2 (indexEnd + indexOf2) array2))

main : Element
main =
  show (sublist [10..100001] [1..100000])
Contributor

rebelwarrior commented Apr 5, 2016

Here is another weird thing I tried it on try elm and reproduced the error with this code. So it seems to be an intermittent issue with very large Arrays. Note that changing the end number of the first array up or down one digit makes the error go away and so does making it larger say by adding a zero.

module Sublist (..) where

import Array
import Graphics.Element exposing (..)
import Debug exposing (..)

sublist : List comparable -> List comparable -> String
sublist list1 list2 =
  let
    size1 = List.length list1
    size2 = List.length list2
  in
    if list1 == list2 then
      "Equal"
    else if List.isEmpty list1 && not (List.isEmpty list2) then
      "Sublist"
    else if List.isEmpty list2 && not (List.isEmpty list1) then
      "Superlist"
    else if size1 <= size2 && isSublistOf list1 list2 then
      "Sublist"
    else if size2 <= size1 && isSublistOf list2 list1 then
      "Superlist"
    else
      "Unequal"

isSublistOf list1 list2 =
  let
    array1 = Array.fromList list1
    array2 = Array.fromList list2
  in
    -- check recursively if array2 indexes match first element of array1
    -- if so check if it fits
    checkArrayEl_r array1 array2 0

checkArrayEl_r : Array.Array a -> Array.Array a -> Int -> Bool
checkArrayEl_r array1 array2 indexOf2 =
  case (Array.get indexOf2 array2) of
    Nothing -> False
    Just el2 ->
      case (Array.get 0 array1) of
        Nothing -> False
        Just el1 ->
          if el1 /= el2 then
            checkArrayEl_r array1 array2 (indexOf2 + 1)
          else
            ifArrayFits array1 array2 indexOf2

ifArrayFits : Array.Array a -> Array.Array a -> Int -> Bool
ifArrayFits array1 array2 indexOf2 =
  -- Code below is producing an error and it should not...
  -- TypeError: Cannot read property 'height' of undefined
  let
    indexEnd = (Array.length array1)
    x = log ((toString indexOf2) ++ "---------**------")
    -- indexEnd = 133
  in
    (array1 == (Array.slice indexOf2 (indexEnd + indexOf2) array2))

main : Element
main =
  show (sublist [10..100001] [1..100000])
@rebelwarrior

This comment has been minimized.

Show comment
Hide comment
@rebelwarrior

rebelwarrior Apr 5, 2016

Contributor

That's true @jvoigtlaender it maybe the solution to one may fix the other. Slice is definitely funky for Arrays.

Contributor

rebelwarrior commented Apr 5, 2016

That's true @jvoigtlaender it maybe the solution to one may fix the other. Slice is definitely funky for Arrays.

@evancz evancz referenced this issue Jun 25, 2016

Closed

array problems #649

@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.

@evancz evancz closed this Jun 25, 2016

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