bazel analysis/skylark: fix crash in attr.int(default=<function>)

The type of the default=... parameter of each of the attr.<type> functions
was inconsistent with the Param.type or Param.allowed_types annotations,
causing the annotation-based type-check to accept a StarlarkFunction value,
but the reflective call to then fail.

This CL removes StarlarkFunction from Param.allowed_types for these parameters:

   attr.int(default=function)
   attr.int_list(default=function)
   attr.string(default=function)
   attr.string_list(default=function)
   attr.bool(default=function)
   attr.string_dict(default=function)
   attr.string_list_dict(default=function)

Only these label-oriented attribute types accept a function:

  attr.label,
  attr.label_list
  attr.label_keyed_string_dict
  attr.output                     \ the default parameter
  attt.output_list                / is deprecated for these

CL 285849424 fixes the annotation processor to detect this and similar errors.
It catches other instances and does other checks, so it is split off as a separate change.

Also:
- move the nasty little optionMap function out of EvalUtils (where its
  generic type forces it to abuse unsafe casts) and into SkylarkAttr.
  (The only other use, in a test, was trivially replaced by simpler code.)
- use Map not Dict for the map produced by optionMap.

See github.com/bazelbuild/bazel/issues/9463.

PiperOrigin-RevId: 286037108
5 files changed
tree: 9d676c3500609bd85102cfa71e789cf25d5c2e5a
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
README.md

Bazel

{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.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status