Skip to content
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

Fails a destructuring assignment when declaration with const. #257

Closed
Kray-G opened this issue Mar 30, 2021 · 1 comment
Closed

Fails a destructuring assignment when declaration with const. #257

Kray-G opened this issue Mar 30, 2021 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Kray-G
Copy link
Owner

Kray-G commented Mar 30, 2021

Here is the code.

function test1(data) {
    var [a, b, ...c] = data.split(',');
}
function test2(data) {
    [a, b, ...c] = data.split(',');
}
function test3(data) {
    const [a, b, ...c] = data.split(',');
}

Only test3 is failed with raising an exception. The cause is that the bytecode is different from other 2 functions.
The bytecode is below.

test1: (unknown)(1 - 3)
  .L2997
    35a3:   enter                   21, vars(4), args(1)
    35a4:   pushs                   ","
    35a5:   pushvl0                 $0(0)
    35a6:   calls                   "split", 1
    35a7:   pushlv                  $0(1)
    35a8:   getaryv                 0
    35a9:   pushlv                  $0(2)
    35aa:   getaryv                 1
    35ab:   pushlv                  $0(3)
    35ac:   getarya                 2
    35ad:   pop
    35ae:   ret                     null
    35af:   halt

test2: (unknown)(4 - 6)
  .L2998
    35b0:   enter                   21, vars(4), args(1)
    35b1:   pushs                   ","
    35b2:   pushvl0                 $0(0)
    35b3:   calls                   "split", 1
    35b4:   pushlv                  $0(1)
    35b5:   getaryv                 0
    35b6:   pushlv                  $0(2)
    35b7:   getaryv                 1
    35b8:   pushlv                  $0(3)
    35b9:   getarya                 2
    35ba:   pop
    35bb:   ret                     null
    35bc:   halt

test3: (unknown)(7 - 9)
  .L2999
    35bd:   enter                   21, vars(4), args(1)
    35be:   pushs                   ","
    35bf:   pushvl0                 $0(0)
    35c0:   calls                   "split", 1
    35c1:   dup
    35c2:   applyvi                 0
    35c3:   pushvl0                 $0(1)
    35c4:   eqeq
    35c5:   throwifz                NoMatchingPatternException
    35c6:   dup
    35c7:   applyvi                 1
    35c8:   pushvl0                 $0(2)
    35c9:   eqeq
    35ca:   throwifz                NoMatchingPatternException
    35cb:   pushlv                  $0(3)
    35cc:   getarya                 2
    35cd:   pop
    35ce:   ret                     null
    35cf:   halt
@Kray-G Kray-G added the bug Something isn't working label Mar 30, 2021
@Kray-G Kray-G added this to the v1.1.0 milestone Mar 30, 2021
@Kray-G Kray-G self-assigned this Mar 30, 2021
@Kray-G
Copy link
Owner Author

Kray-G commented Mar 30, 2021

AST for those are same.

(=):fnc, depth:0
  *(fnc:test1)(unknown) [0:70]
  (function: test1)(unknown) [refs:0]
    (argument)
      -(var:data):unknown [0:0]
    (block)
      var (=):obj, depth:0
        (make-array):obj
          *(var:a):unknown [0:1]
          *(var:b):unknown [0:2]
          (spread)
            -(var:c):unknown [0:3]
        (call):unknown
          (ref):unknown, depth:0
            -(var:data):unknown [0:0]
            (s:"split"):cstr
          (s:","):cstr
    (return)
(=):fnc, depth:0
  *(fnc:test2)(unknown) [0:71]
  (function: test2)(unknown) [refs:0]
    (argument)
      -(var:data):unknown [0:0]
    (block)
      (=):obj, depth:0
        (make-array):obj
          *(var:a):unknown [0:1]
          *(var:b):unknown [0:2]
          (spread)
            -(var:c):unknown [0:3]
        (call):unknown
          (ref):unknown, depth:0
            -(var:data):unknown [0:0]
            (s:"split"):cstr
          (s:","):cstr
    (return)
(=):fnc, depth:0
  *(fnc:test3)(unknown) [0:72]
  (function: test3)(unknown) [refs:0]
    (argument)
      -(var:data):unknown [0:0]
    (block)
      const (=):obj, depth:0
        (make-array):obj
          *(var:a):unknown [0:1]
          *(var:b):unknown [0:2]
          (spread)
            -(var:c):unknown [0:3]
        (call):unknown
          (ref):unknown, depth:0
            -(var:data):unknown [0:0]
            (s:"split"):cstr
          (s:","):cstr
    (return)

Kray-G added a commit that referenced this issue Mar 30, 2021
Kray-G added a commit that referenced this issue Mar 30, 2021
Kray-G added a commit that referenced this issue Mar 30, 2021
Kray-G added a commit that referenced this issue Mar 31, 2021
Kray-G added a commit that referenced this issue Mar 31, 2021
@Kray-G Kray-G closed this as completed in da857d6 Mar 31, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Kray-G added a commit that referenced this issue Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant