Skip to content

Official example of variables gives syntax error: template: :1: unexpected ".0" in operand #2209

@your-diary

Description

@your-diary

Description

How to reproduce:

  1. Visit the documentation of variables.

  2. Copy and paste the example in it:

    version: 3
    
    tasks:
      foo:
        vars:
          STRING: 'Hello, World!'
          BOOL: true
          INT: 42
          FLOAT: 3.14
          ARRAY: [1, 2, 3]
          MAP:
            map: {A: 1, B: 2, C: 3}
        cmds:
          - 'echo {{.STRING}}'  # Hello, World!
          - 'echo {{.BOOL}}'    # true
          - 'echo {{.INT}}'     # 42
          - 'echo {{.FLOAT}}'   # 3.14
          - 'echo {{.ARRAY}}'   # [1 2 3]
          - 'echo {{.ARRAY.0}}' # 1
          - 'echo {{.MAP}}'     # map[A:1 B:2 C:3]
          - 'echo {{.MAP.A}}'   # 1
  3. Execute task foo command.

  4. It gives syntax error:

    template: :1: unexpected ".0" in operand
    

The cause is this line:

- 'echo {{.ARRAY.0}}' # 1

Maybe we should use index function instead (i.e. index .ARRAY 0)?
Or is there any more concise syntax supported?

Version

3.43.2

Operating system

macOS

Experiments Enabled

No response

Example Taskfile

version: 3

tasks:
  foo:
    vars:
      STRING: 'Hello, World!'
      BOOL: true
      INT: 42
      FLOAT: 3.14
      ARRAY: [1, 2, 3]
      MAP:
        map: {A: 1, B: 2, C: 3}
    cmds:
      - 'echo {{.STRING}}'  # Hello, World!
      - 'echo {{.BOOL}}'    # true
      - 'echo {{.INT}}'     # 42
      - 'echo {{.FLOAT}}'   # 3.14
      - 'echo {{.ARRAY}}'   # [1 2 3]
      - 'echo {{.ARRAY.0}}' # 1
      - 'echo {{.MAP}}'     # map[A:1 B:2 C:3]
      - 'echo {{.MAP.A}}'   # 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: docsChanges related to documentation.good first issueIssues that are good for first-time contributors to pick up.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions