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

False Positive for Object Element Dereference #66

Closed
Kurt-von-Laven opened this issue Oct 30, 2021 · 8 comments
Closed

False Positive for Object Element Dereference #66

Kurt-von-Laven opened this issue Oct 30, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@Kurt-von-Laven
Copy link

Actionlint knows about array element dereferences, but not object element dereferences. For example, GitHub Actions supports the syntax ${{ join(needs.*.result, ' ') }} as documented in slack-templates' README despite the fact that needs is not an array. Actionlint 1.6.6 yields an error message of the following form:

[...]/.github/workflows/test.yaml:[row]:[col]: receiver of array element dereference must be type of array but got "{<job_id_1>: {outputs: {}; result: string}; <job_id_2>: {outputs: {}; result: string}}" [expression]
         |
[row] |           results: ${{ join(needs.*.result, ' ') }}

Thank you for creating Actionlint! It's quite nice to have a super easy way to check whether an action has syntax errors without wasting build credits.

@alambike
Copy link

alambike commented Nov 3, 2021

We are seeing the same thing here with this expression:

      - name: Check failures
        if: ${{ contains(steps.*.outcome, 'failure') }}

.github/workflows/test.yml:128:26: receiver of array element dereference must be type of array but got "{pre: {outcome: string; outputs: {string => string}; conclusion: string}; pro: {outputs: {string => string}; conclusion: string; outcome: string}; metadata: {outputs: {string => string}; conclusion: string; outcome: string}; des: {conclusion: string; outcome: string; outputs: {string => string}}}" [expression]
    |
128 |         if: ${{ contains(steps.*.outcome, 'failure') }}
    |                          ^~~~~~~~~~~~~~~~

@rhysd rhysd added the bug Something isn't working label Nov 7, 2021
@rhysd
Copy link
Owner

rhysd commented Nov 7, 2021

Thank you for reporting this. It looks a bug of actionlint.

@rhysd
Copy link
Owner

rhysd commented Nov 7, 2021

https://docs.github.com/en/actions/learn-github-actions/expressions#object-filters

The document only mentions arrays as target of object filtering. So I thought the syntax was only for arrays when I implemented the type check. I think it was incorrect.

@Kurt-von-Laven
Copy link
Author

Kurt-von-Laven commented Nov 7, 2021

Indeed; I noticed this as well when trying to find a link that would prove the syntax was supported and was pleasantly surprised that it was when I first tried it. I filed the issue linked above with GitHub to enhance their documentation accordingly.

@rhysd
Copy link
Owner

rhysd commented Nov 8, 2021

I tried

- run: |
    echo '${{ toJSON(fromJSON(env.JSON).*.foo) }}'
  env:
    JSON: '{"a": {"foo": "from a"}, "b": {"foo": "from b"}}'

and confirmed output

[
  "from a",
  "from b"
]

https://github.com/rhysd/actionlint/runs/4136626284?check_suite_focus=true

@rhysd rhysd closed this as completed in cabbf84 Nov 8, 2021
@rhysd
Copy link
Owner

rhysd commented Nov 8, 2021

With cabbf84, x.* is deduced to array<any> even if x is an object. This can prevent the false positive reported in this issue.

@rhysd
Copy link
Owner

rhysd commented Nov 8, 2021

The fix was released as v1.6.7

@Kurt-von-Laven
Copy link
Author

I can confirm that this fix is working for us. Thank you!

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

3 participants