Skip to content

go/types: conf.check complains about a function is not declared in a package #19334

Closed
@jzhu077

Description

@jzhu077

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jzhu/projects"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build240680793=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

	conf := types.Config{Importer: importer.Default()}
	info := &types.Info{Types: make(map[ast.Expr]types.TypeAndValue)}
	if _, err := conf.Check(filepath, fset, []*ast.File{f}, info); err != nil {
		log.Fatal(err) // type error
	}

hello.go

package main

import (
	"fmt"
	"github.com/codelingo/sandbox/test1/animal"
)

func main() {
	a := animal.New()
	c := a.Name
	fmt.Println(c)
	//d := animal.Num()
	//fmt.Println(d)
}

animal.go

package animal

type ani struct {
	Limbs int
	Eyes  int
	Name  string
}

func New() *ani {
	return &ani{
		Limbs: 4,
		Eyes:  2,
		Name:  "cat",
	}
}

//func Num() int {
//	return 6
//}

What did you expect to see? ### What did you see instead?

It runs perfectly without those commented lines, however when I uncomment them. The config.check gives an error

hello.go:12:7: Num not declared by package animal

I have tested it with

go run hello.go 

after uncomment those lines. It does what it suppose to do.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions