Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"gop export" errir export "github.com/xx/yy" error: 25:91: expected ')', found '/' #635

Closed
456vv opened this issue Dec 23, 2020 · 6 comments
Labels

Comments

@456vv
Copy link

456vv commented Dec 23, 2020

export "github.com/xx/vweb/yy" error: 25:91: expected ')', found '/'
export "github.com/xx/vweb/yy" error: empty exported package

occurred error:

type ServerTLSFile struct {
    CertFile, KeyFile   string
}
func (T *ServerHTTP) LoadTLS(config *tls.Config, files []ServerTLSFile) error {
	...
}

no error:

type ServerTLSFile struct {
    CertFile, KeyFile   string
}
func (T *ServerHTTP) LoadTLS(config *tls.Config, files []*ServerTLSFile) error {
	...
}

problem is []ServerTLSFile not recognized

@456vv
Copy link
Author

456vv commented Dec 23, 2020

types.Type 内部是以pkg.Path路径来生成做库名。造成后面无法正常的验证代码。所以报错。
文件地址:github.com\goplus\gop\cmd\internal\export\gopkg\exporter.go
可以这样修复它,或许你有更好方法,原因我不是很了解你们的代码:

func (p *Exporter) typeString(typ types.Type) string {
	if typNamed, ok := typ.(*types.Named); ok {
		typName := typNamed.Obj().Name()
		objPkg := typNamed.Obj().Pkg()
		if objPkg == nil {
			return typName
		}
		pkgName := objPkg.Name()
		return pkgName+"."+typName
	}
	typStr := typ.String()
	if !strings.Contains(typStr, ".") {
		return typStr
	}
	return p.fixPkgString(typ.String())
}

@456vv
Copy link
Author

456vv commented Dec 23, 2020

这样很好:

func (p *Exporter) typeString(typ types.Type) string {
	typStr := types.TypeString(typ, func(pkg *types.Package) string {
		if pkg == nil {
			return ""
		}
		return pkg.Name()
	})
	return typStr
}

@456vv
Copy link
Author

456vv commented Dec 25, 2020

func (p *Exporter) typeString(typ types.Type) string {
	typStr := types.TypeString(typ, func(pkg *types.Package) string {
		if pkg == nil {
			return ""
		}
		if name, ok := p.imports[pkg.Path()]; ok {
			return name
		}
		fmt.Printf("imports list -not find '%s', used by default name '%s'\n", pkg.Path(), pkg.Name())
		return pkg.Name()
	})
	return typStr
}

@visualfc
Copy link
Member

visualfc commented Dec 28, 2020

@456vv 建议提交 pull request,以便集成测试。

@456vv
Copy link
Author

456vv commented Dec 28, 2020

#638 这里文件已经修复gop export 错误。已测正常。

type A interface{
    error
}

不完美的地方就是会导出:

error.Error
A.Error

不过不影响使用,对你们项目代码流程不熟悉,暂免 pull request,你们自己处理一下吧。

@xushiwei xushiwei added the bug label Jan 7, 2021
@xushiwei
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants