#24469·bazel

Should inline lambdas be allowed as the test for an `if CompClause`

Author: lgalfasoCreated Nov 23, 2024Updated Sep 16, 2026
Labelstype: bugP2team-Starlark-Interpreter

Description of the bug:

The following syntax is allowed in Starlark:

[a for a in range(10) if lambda: True]

This is not allowed in Python. Should this syntax be allowed?

Maybe related context: The following syntax is currently forbidden in both Starlark and Python

print(1 if lambda: True else 2)

and the following syntax is allowed in both Starlark and Python

print(1 if (lambda: True) else 2)
[a for a in range(10) if (lambda: True)]

Which category does this issue belong to?

Starlark Interpreter

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response