diff options
author | Joe Tsai <joetsai@digital-static.net> | 2020-10-14 18:41:16 -0700 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2021-02-25 21:21:51 +0000 |
commit | b83d073e9eb4cbd0cd5ca530f576668c49f6d0f1 (patch) | |
tree | f706562328a6ff09eec8117618bc5edb100b2466 /src/text | |
parent | 7fcf9893f71c75f6b2fd53bea326d5061f705208 (diff) | |
download | go-b83d073e9eb4cbd0cd5ca530f576668c49f6d0f1.tar.gz go-b83d073e9eb4cbd0cd5ca530f576668c49f6d0f1.zip |
reflect: add Method.IsExported and StructField.IsExported methods
The IsExported method is a more intuitive helper for checking whether
the method or field is exported than checking whether PkgPath is empty.
In the same CL, modify the standard library to make use of this helper.
Fixes #41563
Change-Id: Iaacfb3b74449501f98e2707aa32095a32bd3c3c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/266197
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/text')
-rw-r--r-- | src/text/template/exec.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/text/template/exec.go b/src/text/template/exec.go index 19154fc640..4637b2035f 100644 --- a/src/text/template/exec.go +++ b/src/text/template/exec.go @@ -615,7 +615,7 @@ func (s *state) evalField(dot reflect.Value, fieldName string, node parse.Node, tField, ok := receiver.Type().FieldByName(fieldName) if ok { field := receiver.FieldByIndex(tField.Index) - if tField.PkgPath != "" { // field is unexported + if !tField.IsExported() { s.errorf("%s is an unexported field of struct type %s", fieldName, typ) } // If it's a function, we must call it. |