Move validation of one-annotation-per-symbol to `TypeResolver` This undoes some complication in the resolver by removing the `hasType` parameter to `bind()`. Now, the resolver is agnostic to where type annotations occur, and it's the type resolver's responsibility to complain when an annotation appears somewhere other than the first binding occurrence of a symbol. This makes the story around `DefStatement` simpler. All defs are considered to annotate a `Callable` type to the function identifier, so redefining a function is simply disallowed when running the type resolver. We also get to remove an edge case around illegally reusing param names in the same function signature, since this error would cause the AST to not make it to the type resolver anyway. This also simplifies the implementation of how we decide whether the annotation is at the first binding occurrence. Before, we were basing it on the resolver's internal state. Now we're just checking the `Binding#first` field to see whether it matches the `Identifier` being visited. The entry point to the `TypeResolver` now no longer throws an exception when errors exist. The caller checks that, just like for `Resolver`. Moved relevant test cases from `ResolverTest` to `TypeResolverTest` and simplified some of them. Also added a test for attempting to annotate a loaded global (not shadowed) symbol. Updated `StarlarkTypesTest` to simplify the detection of whether or not the type resolver ran, based on bad annotations rather than function redefinitions. Also simplified assertion logic in that file to use better primitives. (Previously we were intercepting an `AssertionError` thrown by the `failFastHandler` in some test cases.) Work toward #27728. PiperOrigin-RevId: 845389905 Change-Id: I98a429d8d4db3a8e3208b3a60856b048bba4f4ab
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.
See CONTRIBUTING.md