Can't use anchor for anchor

Issue #467 wontfix
Inetov created an issue

This YAML will fail:

test-list:
 - &1
   a: 1
   b: 2

 - &2 <<: *1

 - &3 <<: *1

 - <<: *2

Replacing “2” to “1” in last line will fix it. Why?

I сhoose this priority because this functionality is needed for my project, but I can use “1” even though it is not convenient.

Comments (10)

  1. Andrey Somov

    I think you found a bug. It will not be easy to fix.

    The problem is that the node “<<: *2” is parsed as scalar but it represents a mapping.

    The same bug is in PyYAML.

  2. Inetov reporter

    more realistic example:

    settings-list:
     - &1
       a: 1
       b: 2
       c: 3  #and many more params.
    
     - &2 <<: *1
       a: 11
       b: 22
    
     - &3 <<: *2
       c: 5
    
    
    some-object:
     properties: *2
    
    another-object:
     properties: *3
    

    works as expected here

  3. Andrey Somov

    Please be aware that merging is very controversial feature.
    It has been removed in the next spec. YAML 1.2 does not have the merge.

    That is why the SnakeYAML Engine does not implement merging.

  4. Inetov reporter

    What is “another interpreter“ ?

    never mind, I was wrong.

    YAML 1.2 does not have the merge.

    Here is how! I did not know.
    Ok and how do I use anchors correctly?

    I added a test.

    not understood. where?

  5. Andrey Somov

    Ok and how do I use anchors correctly?

    you use them correctly. But you use merge tag “<<“ together with aliases. This tag is deprecated and removed in the next spec YAML 1.2

    not understood. where?

    check the latest source code

  6. Log in to comment