Go   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了关闭golang 的 variable declared but not used和package大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_616_0@ @H_502_1@觉得golang的 variable declared but not used 和 package imported but not used 在调试代码的时候很不方便!!!!!! 这么多语言中只有golang会有变量不使用,包引用不用报错的!

@H_616_0@ 有没有方法去掉这两个验证? 再上生产的时候开启验证再改代码?

方法: 修改golang源码,将error错误改成warn错误(在eclipse上都会显示红色错误,但warn不影响编译),重新编译源码.

1 解决:declared but not used
修改go/src/cmd/gc/walk.c
for(l=fn->dcl;l;l=l->next){
if(l->n->op!=ONAME||(l->n->class&~PHEAp)!=PAUTO||l->n->sym->name[0]=='&'||l->n->used)
conTinue;
if(l->n->defn&&l->n->defn->op==OTYPESW){
if(l->n->defn->left->used)
conTinue;
lineno=l->n->defn->left->lineno;
warn("%s declared and not used",l->n->sym);
l->n->defn->left->used=1;// suppress repeats
} else {
lineno = l->n->lineno;
// 此处修改
// yyerror("%s declared and not used,l->n->sym); // life
}
}

2 解决imported but not used:
修改:go/src/cmd/gc/lex.c
if ( s -> def -> op == OPACK ) {
// throw away top-level package name leftover
// from prevIoUs file.
// leave s->block set to cause redeclaration
// errors if a conflicTing top-level name is
// introduced by a different file.
if(!s->def->used && !nSyntaxerrors) {
lineno = s->def->lineno;
warn("imported and not used: \"%Z\"",s->def->pkg->path);
}
s->def = N;
conTinue;
}

@H_616_0@ 本文之前发布在google group golang-china上:https://groups.google.com/forum/?fromgroups#!topic/golang-china/W0WMC__2NO8

大佬总结

以上是大佬教程为你收集整理的关闭golang 的 variable declared but not used和package全部内容,希望文章能够帮你解决关闭golang 的 variable declared but not used和package所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。