8000 Using the three dots format to add items to an array gives an error · Issue #2718 · symfony/ux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Using the three dots format to add items to an array gives an error #2718

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

Closed
fabioflx opened this issue May 7, 2025 · 9 comments
Closed
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed

Comments

@fabioflx
Copy link
fabioflx commented May 7, 2025

Since v3.21.x, clearing the cache of a Symfony project fails if twig files use the "three dots" format to add circumstantial elements to an array.
The following code works on v3.20.x instead:

{% set condition = true %}
{% include 'component.json.twig' with {
  items: [
    include('something1.json.twig', {}),
    ...condition ? [include('something2.json.twig', {})] : []
  ]
%}
@fabioflx fabioflx added the Bug Bug Fix label May 7, 2025
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label May 7, 2025
@smnandre
Copy link
Member
smnandre commented May 7, 2025

Did you try with parenthesis here ?

    ...(condition ? [include('something2.json.twig', {})] : [])

Also i'm a bit surprised include('something2.json.twig', {}) is used here as a way to get values ... 🤔

@fabioflx
Copy link
Author
fabioflx commented May 7, 2025

Did you try with parenthesis here ?

...(condition ? [include('something2.json.twig', {})] : [])

Also i'm a bit surprised include('something2.json.twig', {}) is used here as a way to get values ... 🤔

Thank you, but I tried with parenthesis and it gives the same error.
Please don't mind the include part as it's just an example; the error is in the "..." part even when you use something much easier like ...true ? [] : []

@smnandre
Copy link
Member
smnandre commented May 7, 2025

Could you show the exact code in question, for us to try to help ?

@Kocal
Copy link
Member
Kocal commented May 8, 2025

What is the error?

@fabioflx
Copy link
Author
fabioflx commented May 8, 2025

Ok, this real code does not work:

{% set something = [
    ...true ? ['a'] : ['b']
  ]
%}

The error line reads:
14:35:28 CRITICAL [php] Uncaught Error: syntax error, unexpected token "..." ["exception" => ParseError { …}]

@Kocal
Copy link
Member
Kocal commented May 9, 2025

Then it's more an issue from Twig? What version of Twig do you use ?

@fabioflx
Copy link
Author
fabioflx commented May 9, 2025

Then it's more an issue from Twig? What version of Twig do you use ?

The error is on v3.21.x but the code works on v3.20.x.
I notified the issue on Twig project too, thank you

@smnandre
Copy link
Member

Just tested, this exact code works on 3.21

    {% set something = [
        ...(true ? ['a'] : ['b'])
      ]
    %}

    {{ something|json_encode }}

Without parenthesis, it does produce the following error

syntax error, unexpected token "..."

@smnandre
Copy link
Member

Deciding if it's a bug will not something we can do here. So i'm closing here and let you continue the discussion on the twig topic indeed.

@smnandre smnandre closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Needs Review Needs to be re 3DE4 viewed
Projects
None yet
Development

No branches or pull requests

4 participants
0