2013-05-28 13:28:46 -06:00
|
|
|
package ssa_test
|
|
|
|
|
2013-07-15 16:09:18 -06:00
|
|
|
// This file defines tests of source-level debugging utilities.
|
2013-05-28 13:28:46 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"go/ast"
|
|
|
|
"go/parser"
|
|
|
|
"go/token"
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
"regexp"
|
2013-05-28 13:28:46 -06:00
|
|
|
"testing"
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
|
|
|
|
"code.google.com/p/go.tools/go/exact"
|
|
|
|
"code.google.com/p/go.tools/go/types"
|
|
|
|
"code.google.com/p/go.tools/importer"
|
|
|
|
"code.google.com/p/go.tools/ssa"
|
2013-05-28 13:28:46 -06:00
|
|
|
)
|
|
|
|
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
func TestObjValueLookup(t *testing.T) {
|
|
|
|
imp := importer.New(new(importer.Context)) // (uses GCImporter)
|
|
|
|
f, err := parser.ParseFile(imp.Fset, "testdata/objlookup.go", nil, parser.DeclarationErrors|parser.ParseComments)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("parse error: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maps each var Ident (represented "name:linenum") to the
|
2013-07-16 11:50:08 -06:00
|
|
|
// kind of ssa.Value we expect (represented "Constant", "&Alloc").
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
expectations := make(map[string]string)
|
|
|
|
|
|
|
|
// Find all annotations of form x::BinOp, &y::Alloc, etc.
|
|
|
|
re := regexp.MustCompile(`(\b|&)?(\w*)::(\w*)\b`)
|
|
|
|
for _, c := range f.Comments {
|
|
|
|
text := c.Text()
|
|
|
|
pos := imp.Fset.Position(c.Pos())
|
|
|
|
for _, m := range re.FindAllStringSubmatch(text, -1) {
|
|
|
|
key := fmt.Sprintf("%s:%d", m[2], pos.Line)
|
|
|
|
value := m[1] + m[3]
|
|
|
|
expectations[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info, err := imp.CreateSourcePackage("main", []*ast.File{f})
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
prog := ssa.NewProgram(imp.Fset, ssa.DebugInfo /*|ssa.LogFunctions*/)
|
|
|
|
prog.CreatePackages(imp)
|
|
|
|
pkg := prog.Package(info.Pkg)
|
|
|
|
pkg.Build()
|
|
|
|
|
|
|
|
// Gather all idents and objects in file.
|
|
|
|
objs := make(map[types.Object]bool)
|
|
|
|
var ids []*ast.Ident
|
|
|
|
ast.Inspect(f, func(n ast.Node) bool {
|
|
|
|
if id, ok := n.(*ast.Ident); ok {
|
|
|
|
ids = append(ids, id)
|
|
|
|
if obj := info.ObjectOf(id); obj != nil {
|
|
|
|
objs[obj] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
// Check invariants for func and const objects.
|
|
|
|
for obj := range objs {
|
|
|
|
switch obj := obj.(type) {
|
|
|
|
case *types.Func:
|
|
|
|
if obj.Name() == "interfaceMethod" {
|
|
|
|
continue // TODO(adonovan): not yet implemented.
|
|
|
|
}
|
|
|
|
checkFuncValue(t, prog, obj)
|
|
|
|
|
|
|
|
case *types.Const:
|
|
|
|
checkConstValue(t, prog, obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check invariants for var objects.
|
|
|
|
// The result varies based on the specific Ident.
|
|
|
|
for _, id := range ids {
|
|
|
|
if obj, ok := info.ObjectOf(id).(*types.Var); ok {
|
2013-07-15 16:09:18 -06:00
|
|
|
ref, _ := importer.PathEnclosingInterval(f, id.Pos(), id.Pos())
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
pos := imp.Fset.Position(id.Pos())
|
|
|
|
exp := expectations[fmt.Sprintf("%s:%d", id.Name, pos.Line)]
|
|
|
|
if exp == "" {
|
|
|
|
t.Errorf("%s: no expectation for var ident %s ", pos, id.Name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
wantAddr := false
|
|
|
|
if exp[0] == '&' {
|
|
|
|
wantAddr = true
|
|
|
|
exp = exp[1:]
|
|
|
|
}
|
|
|
|
checkVarValue(t, prog, ref, obj, exp, wantAddr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkFuncValue(t *testing.T, prog *ssa.Program, obj *types.Func) {
|
|
|
|
v := prog.FuncValue(obj)
|
|
|
|
// fmt.Printf("FuncValue(%s) = %s\n", obj, v) // debugging
|
|
|
|
if v == nil {
|
|
|
|
t.Errorf("FuncValue(%s) == nil", obj)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// v must be an *ssa.Function or *ssa.Builtin.
|
|
|
|
v2, _ := v.(interface {
|
|
|
|
Object() types.Object
|
|
|
|
})
|
|
|
|
if v2 == nil {
|
|
|
|
t.Errorf("FuncValue(%s) = %s %T; has no Object() method",
|
|
|
|
obj, v.Name(), v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if vobj := v2.Object(); vobj != obj {
|
|
|
|
t.Errorf("FuncValue(%s).Object() == %s; value was %s",
|
|
|
|
obj, vobj, v.Name())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !types.IsIdentical(v.Type(), obj.Type()) {
|
|
|
|
t.Errorf("FuncValue(%s).Type() == %s", obj, v.Type())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkConstValue(t *testing.T, prog *ssa.Program, obj *types.Const) {
|
2013-07-16 11:50:08 -06:00
|
|
|
c := prog.ConstValue(obj)
|
|
|
|
// fmt.Printf("ConstValue(%s) = %s\n", obj, c) // debugging
|
|
|
|
if c == nil {
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
t.Errorf("ConstValue(%s) == nil", obj)
|
|
|
|
return
|
|
|
|
}
|
2013-07-16 11:50:08 -06:00
|
|
|
if !types.IsIdentical(c.Type(), obj.Type()) {
|
|
|
|
t.Errorf("ConstValue(%s).Type() == %s", obj, c.Type())
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if obj.Name() != "nil" {
|
2013-07-16 11:50:08 -06:00
|
|
|
if !exact.Compare(c.Value, token.EQL, obj.Val()) {
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
t.Errorf("ConstValue(%s).Value (%s) != %s",
|
2013-07-16 11:50:08 -06:00
|
|
|
obj, c.Value, obj.Val())
|
go.tools/ssa: add debug information for all ast.Idents.
This CL adds three new functions to determine the SSA Value
for a given syntactic var, func or const object:
Program.{Const,Func,Var}Value.
Since constants and functions are immutable, the first
two only need a types.Object; but each distinct
reference to a var may return a distinct Value, so the third
requires an ast.Ident parameter too.
Debug information for local vars is encoded in the
instruction stream in the form of DebugRef instructions,
which are a no-op but relate their operand to a particular
ident in the AST. The beauty of this approach is that it
naturally stays consistent during optimisation passes
(e.g. lifting) without additional bookkeeping.
DebugRef instructions are only generated if the DebugMode
builder flag is set; I plan to make the policy more fine-
grained (per function).
DebugRef instructions are inserted for:
- expr(Ident) for rvalue idents
- address.store() for idents that update an lvalue
- address.address() for idents that take address of lvalue
(this new method replaces all uses of lval.(address).addr)
- expr() for all constant expressions
- local ValueSpecs with implicit zero initialization (no RHS)
(this case doesn't call store() or address())
To ensure we don't forget to emit debug info for uses of Idents,
we must use the lvalue mechanism consistently. (Previously,
many simple cases had effectively inlined these functions.)
Similarly setCallFunc no longer inlines expr(Ident).
Also:
- Program.Value() has been inlined & specialized.
- Program.Package() has moved nearer the new lookup functions.
- refactoring: funcSyntax has lost paramFields, resultFields;
gained funcType, which provides access to both.
- add package-level constants to Package.values map.
- opt: don't call localValueSpec for constants.
(The resulting code is always optimised away.)
There are a number of comments asking whether Literals
should have positions. Will address in a follow-up.
Added tests of all interesting cases.
R=gri
CC=golang-dev
https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkVarValue(t *testing.T, prog *ssa.Program, ref []ast.Node, obj *types.Var, expKind string, wantAddr bool) {
|
|
|
|
// The prefix of all assertions messages.
|
|
|
|
prefix := fmt.Sprintf("VarValue(%s @ L%d)",
|
|
|
|
obj, prog.Fset.Position(ref[0].Pos()).Line)
|
|
|
|
|
|
|
|
v := prog.VarValue(obj, ref)
|
|
|
|
|
|
|
|
// Kind is the concrete type of the ssa Value.
|
|
|
|
gotKind := "nil"
|
|
|
|
if v != nil {
|
|
|
|
gotKind = fmt.Sprintf("%T", v)[len("*ssa."):]
|
|
|
|
}
|
|
|
|
|
|
|
|
// fmt.Printf("%s = %v (kind %q; expect %q) addr=%t\n", prefix, v, gotKind, expKind, wantAddr) // debugging
|
|
|
|
|
|
|
|
// Check the kinds match.
|
|
|
|
// "nil" indicates expected failure (e.g. optimized away).
|
|
|
|
if expKind != gotKind {
|
|
|
|
t.Errorf("%s concrete type == %s, want %s", prefix, gotKind, expKind)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the types match.
|
|
|
|
// If wantAddr, the expected type is the object's address.
|
|
|
|
if v != nil {
|
|
|
|
expType := obj.Type()
|
|
|
|
if wantAddr {
|
|
|
|
expType = types.NewPointer(expType)
|
|
|
|
}
|
|
|
|
if !types.IsIdentical(v.Type(), expType) {
|
|
|
|
t.Errorf("%s.Type() == %s, want %s", prefix, v.Type(), expType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|