Replace OptionalPath.valid flag by checking the path itself.

Test: m nothing
Change-Id: Iaf7655e4676d2beeb7c7ac3bcba11a7dad4a01a3
This commit is contained in:
Martin Stjernholm
2021-09-16 14:11:12 +01:00
parent 14cdd71152
commit 2fee27f3c9

View File

@@ -263,27 +263,23 @@ func ResPathWithName(ctx ModuleOutPathContext, p Path, name string) ModuleResPat
// OptionalPath is a container that may or may not contain a valid Path.
type OptionalPath struct {
valid bool
path Path
path Path // nil if invalid.
}
// OptionalPathForPath returns an OptionalPath containing the path.
func OptionalPathForPath(path Path) OptionalPath {
if path == nil {
return OptionalPath{}
}
return OptionalPath{valid: true, path: path}
return OptionalPath{path: path}
}
// Valid returns whether there is a valid path
func (p OptionalPath) Valid() bool {
return p.valid
return p.path != nil
}
// Path returns the Path embedded in this OptionalPath. You must be sure that
// there is a valid path, since this method will panic if there is not.
func (p OptionalPath) Path() Path {
if !p.valid {
if p.path == nil {
panic("Requesting an invalid path")
}
return p.path
@@ -294,7 +290,7 @@ func (p OptionalPath) Path() Path {
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
// this OptionalPath.
func (p OptionalPath) AsPaths() Paths {
if !p.valid {
if p.path == nil {
return nil
}
return Paths{p.path}
@@ -303,7 +299,7 @@ func (p OptionalPath) AsPaths() Paths {
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
// result of calling Path.RelativeToTop on it.
func (p OptionalPath) RelativeToTop() OptionalPath {
if !p.valid {
if p.path == nil {
return p
}
p.path = p.path.RelativeToTop()
@@ -312,7 +308,7 @@ func (p OptionalPath) RelativeToTop() OptionalPath {
// String returns the string version of the Path, or "" if it isn't valid.
func (p OptionalPath) String() string {
if p.valid {
if p.path != nil {
return p.path.String()
} else {
return ""