提交 84ce2783 编写于 作者: A aarzilli 提交者: Derek Parker

proc: allow evaluating constants specified with a partial package path

Fixes #1151
上级 918ab760
package main
import (
"dir0/pkg"
"fmt"
"runtime"
)
......@@ -32,5 +33,6 @@ func main() {
e := ConstType(10)
f := BitFieldType(0)
runtime.Breakpoint()
fmt.Println(a, b, c, d, e, f)
pkg.SomeVar.AnotherMethod(2)
fmt.Println(a, b, c, d, e, f, pkg.SomeConst)
}
......@@ -13,3 +13,7 @@ func (s *SomeType) AnotherMethod(x int) int {
}
var SomeVar SomeType
const (
SomeConst int = 2
)
......@@ -666,7 +666,7 @@ func (scope *EvalScope) findGlobal(name string) (*Variable, error) {
}
for offset, ctyp := range scope.BinInfo.consts {
for _, cval := range ctyp.values {
if cval.fullName == name {
if cval.fullName == name || strings.HasSuffix(cval.fullName, "/"+name) {
t, err := scope.Type(offset)
if err != nil {
return nil, err
......
......@@ -960,6 +960,7 @@ func TestConstants(t *testing.T) {
{"bitZero", true, "1", "", "main.BitFieldType", nil},
{"bitOne", true, "2", "", "main.BitFieldType", nil},
{"constTwo", true, "2", "", "main.ConstType", nil},
{"pkg.SomeConst", true, "2", "", "int", nil},
}
ver, _ := goversion.Parse(runtime.Version())
if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册