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

WORKSPACE files allow shadowing loads #17480

Closed
illicitonion opened this issue Feb 13, 2023 · 1 comment
Closed

WORKSPACE files allow shadowing loads #17480

illicitonion opened this issue Feb 13, 2023 · 1 comment

Comments

@illicitonion
Copy link
Contributor

Description of the bug:

This is a valid WORKSPACE file:

load("//:one.bzl", "fn")

fn()

load("//:two.bzl", "fn")

fn()

The second fn binding shadows the first one.

This is confusing, and error-prone. I would argue that this should be rejected by Bazel, requiring one of the loads to be renamed.

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

% cat >WORKSPACE <<EOF
load("//:one.bzl", "fn")

fn()

load("//:two.bzl", "fn")

fn()
EOF
% cat >one.bzl <<EOF
def fn():
    print("Hello from one")
EOF
% cat >two.bzl <<EOF
def fn():
    print("Hello from two")
EOF
% touch BUILD.bazel
% bazel query ...            
Starting local Bazel server and connecting to it...
DEBUG: /tmp/bazelplay/one.bzl:2:10: Hello from one
DEBUG: /tmp/bazelplay/two.bzl:2:10: Hello from two
INFO: Empty results
Loading: 1 packages loaded

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

release 6.0.0

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 master; git rev-parse HEAD ?

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

illicitonion added a commit to illicitonion/buildtools that referenced this issue Feb 13, 2023
WORKSPACE files currently allow shadowing loads (see
bazelbuild/bazel#17480), i.e. the following is
valid:

```starlark
load("//:one.bzl", "fn")

fn()

load("//:two.bzl", "fn")

fn()
```

Currently buildozer removes the second load because the symbol was
already loaded. This is incorrect - removing the second load changes the
behaviour of this file.

Instead, only delete a load of the last time it was loaded was from the
same place.
@Wyverald
Copy link
Member

At this point it's very unlikely that we'll spend any energy fixing WORKSPACE bugs; all cycles are devoted to Bzlmod instead. So I'll go ahead and close this, even though it's a very valid bug report.

vladmos pushed a commit to bazelbuild/buildtools that referenced this issue Mar 2, 2023
WORKSPACE files currently allow shadowing loads (see
bazelbuild/bazel#17480), i.e. the following is
valid:

```starlark
load("//:one.bzl", "fn")

fn()

load("//:two.bzl", "fn")

fn()
```

Currently buildozer removes the second load because the symbol was
already loaded. This is incorrect - removing the second load changes the
behaviour of this file.

Instead, only delete a load of the last time it was loaded was from the
same place.
apattidb pushed a commit to databricks/buildtools that referenced this issue May 10, 2024
WORKSPACE files currently allow shadowing loads (see
bazelbuild/bazel#17480), i.e. the following is
valid:

```starlark
load("//:one.bzl", "fn")

fn()

load("//:two.bzl", "fn")

fn()
```

Currently buildozer removes the second load because the symbol was
already loaded. This is incorrect - removing the second load changes the
behaviour of this file.

Instead, only delete a load of the last time it was loaded was from the
same place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants