From 5254d18913a40bc91bc495648e4d60636147da4e Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 23 Oct 2024 03:35:47 -0700 Subject: [PATCH] refactor: add rule.* type assertions (#1961) **What type of PR is this?** > Other **What package or component does this PR mostly affect?** > all --- rule/platform_strings.go | 2 ++ rule/value.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/rule/platform_strings.go b/rule/platform_strings.go index a203a62ca..679ba2d99 100644 --- a/rule/platform_strings.go +++ b/rule/platform_strings.go @@ -68,6 +68,8 @@ type PlatformStrings struct { Platform map[PlatformConstraint][]string } +var _ BzlExprValue = (*PlatformStrings)(nil) + // HasExt returns whether this set contains a file with the given extension. func (ps *PlatformStrings) HasExt(ext string) bool { return ps.firstExtFile(ext) != "" diff --git a/rule/value.go b/rule/value.go index cda5809bb..106e71eb3 100644 --- a/rule/value.go +++ b/rule/value.go @@ -37,6 +37,8 @@ type GlobValue struct { Excludes []string } +var _ BzlExprValue = (*GlobValue)(nil) + func (g GlobValue) BzlExpr() bzl.Expr { patternsValue := ExprFromValue(g.Patterns) globArgs := []bzl.Expr{patternsValue} @@ -72,6 +74,9 @@ type Merger interface { type SortedStrings []string +var _ BzlExprValue = SortedStrings(nil) +var _ Merger = SortedStrings(nil) + func (s SortedStrings) BzlExpr() bzl.Expr { list := make([]bzl.Expr, len(s)) for i, v := range s { @@ -93,6 +98,8 @@ func (s SortedStrings) Merge(other bzl.Expr) bzl.Expr { type UnsortedStrings []string +var _ Merger = UnsortedStrings(nil) + func (s UnsortedStrings) Merge(other bzl.Expr) bzl.Expr { if other == nil { return ExprFromValue(s) @@ -104,6 +111,8 @@ func (s UnsortedStrings) Merge(other bzl.Expr) bzl.Expr { // select expression that picks a string list based on a string condition. type SelectStringListValue map[string][]string +var _ BzlExprValue = SelectStringListValue(nil) + func (s SelectStringListValue) BzlExpr() bzl.Expr { defaultKey := "//conditions:default" keys := make([]string, 0, len(s))