Commit a384b5b9 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

cmd/api: bug fix for goapi's lame type checker

This is blocking me submitting the net fd timeout
CL, since goapi chokes on my constant.

The much more extensive fix to goapi's type checker
in pending review in https://golang.org/cl/6742050

But I'd rather get this quick fix in first.

R=golang-dev, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/6818104
parent 48b739ca
...@@ -331,20 +331,6 @@ const ( ...@@ -331,20 +331,6 @@ const (
loaded loaded
) )
// hardCodedConstantType is a hack until the type checker is sufficient for our needs.
// Rather than litter the code with unnecessary type annotations, we'll hard-code
// the cases we can't handle yet.
func (w *Walker) hardCodedConstantType(name string) (typ string, ok bool) {
switch w.scope[0] {
case "pkg syscall":
switch name {
case "darwinAMD64":
return "bool", true
}
}
return "", false
}
func (w *Walker) Features() (fs []string) { func (w *Walker) Features() (fs []string) {
for f := range w.features { for f := range w.features {
fs = append(fs, f) fs = append(fs, f)
...@@ -596,6 +582,10 @@ func (w *Walker) constValueType(vi interface{}) (string, error) { ...@@ -596,6 +582,10 @@ func (w *Walker) constValueType(vi interface{}) (string, error) {
} }
return constDepPrefix + v.Name, nil return constDepPrefix + v.Name, nil
case *ast.BinaryExpr: case *ast.BinaryExpr:
switch v.Op {
case token.EQL, token.LSS, token.GTR, token.NOT, token.NEQ, token.LEQ, token.GEQ:
return "bool", nil
}
left, err := w.constValueType(v.X) left, err := w.constValueType(v.X)
if err != nil { if err != nil {
return "", err return "", err
...@@ -768,12 +758,7 @@ func (w *Walker) walkConst(vs *ast.ValueSpec) { ...@@ -768,12 +758,7 @@ func (w *Walker) walkConst(vs *ast.ValueSpec) {
var err error var err error
litType, err = w.constValueType(vs.Values[0]) litType, err = w.constValueType(vs.Values[0])
if err != nil { if err != nil {
if t, ok := w.hardCodedConstantType(ident.Name); ok { log.Fatalf("unknown kind in const %q (%T): %v", ident.Name, vs.Values[0], err)
litType = t
err = nil
} else {
log.Fatalf("unknown kind in const %q (%T): %v", ident.Name, vs.Values[0], err)
}
} }
} }
} }
......
...@@ -161,3 +161,9 @@ func (common) OnBothTandBVal() {} ...@@ -161,3 +161,9 @@ func (common) OnBothTandBVal() {}
type EmbedSelector struct { type EmbedSelector struct {
time.Time time.Time
} }
const (
foo = "foo"
foo2 string = "foo2"
truth = foo == "foo" || foo2 == "foo2"
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment