Skip to content

Commit afe67e2

Browse files
committed
removed initializer parameter from newVariableWithLevel
1 parent d08215e commit afe67e2

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

compiler/package.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, impor
160160
var importDecls []*Decl
161161
var importedPaths []string
162162
for _, importedPkg := range typesPkg.Imports() {
163-
c.p.pkgVars[importedPkg.Path()] = c.newVariableWithLevel(importedPkg.Name(), true, "")
163+
c.p.pkgVars[importedPkg.Path()] = c.newVariableWithLevel(importedPkg.Name(), true)
164164
importedPaths = append(importedPaths, importedPkg.Path())
165165
}
166166
sort.Strings(importedPaths)
@@ -647,7 +647,9 @@ func translateFunction(typ *ast.FuncType, stmts []ast.Stmt, outerContext *funcCo
647647
if result.Name() == "_" {
648648
name = "result"
649649
}
650-
c.p.objectVars[result] = c.newVariableWithLevel(name, false, c.zeroValue(result.Type()))
650+
varName := c.newVariableWithLevel(name, false)
651+
c.Printf("%s = %s;", varName, c.zeroValue(result.Type()))
652+
c.p.objectVars[result] = varName
651653
id := ast.NewIdent(name)
652654
c.p.Uses[id] = result
653655
c.resultNames[i] = c.setType(id, result.Type())

compiler/statements.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func (c *funcContext) translateStmt(stmt ast.Stmt, label *types.Label) {
425425
for _, spec := range decl.Specs {
426426
o := c.p.Defs[spec.(*ast.TypeSpec).Name].(*types.TypeName)
427427
c.p.typeNames = append(c.p.typeNames, o)
428-
c.p.objectVars[o] = c.newVariableWithLevel(o.Name(), true, "")
428+
c.p.objectVars[o] = c.newVariableWithLevel(o.Name(), true)
429429
c.p.dependencies[o] = true
430430
}
431431
case token.CONST:

compiler/utils.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ func (c *funcContext) zeroValue(ty types.Type) string {
189189
}
190190

191191
func (c *funcContext) newVariable(name string) string {
192-
return c.newVariableWithLevel(name, false, "")
192+
return c.newVariableWithLevel(name, false)
193193
}
194194

195-
func (c *funcContext) newVariableWithLevel(name string, pkgLevel bool, initializer string) string {
195+
func (c *funcContext) newVariableWithLevel(name string, pkgLevel bool) string {
196196
if name == "" {
197197
panic("newVariable: empty name")
198198
}
@@ -238,10 +238,6 @@ func (c *funcContext) newVariableWithLevel(name string, pkgLevel bool, initializ
238238
return varName
239239
}
240240

241-
if initializer != "" {
242-
c.localVars = append(c.localVars, varName+" = "+initializer)
243-
return varName
244-
}
245241
c.localVars = append(c.localVars, varName)
246242
return varName
247243
}
@@ -282,7 +278,7 @@ func (c *funcContext) objectName(o types.Object) string {
282278

283279
name, found := c.p.objectVars[o]
284280
if !found {
285-
name = c.newVariableWithLevel(o.Name(), o.Parent() == c.p.Pkg.Scope(), "")
281+
name = c.newVariableWithLevel(o.Name(), o.Parent() == c.p.Pkg.Scope())
286282
c.p.objectVars[o] = name
287283
}
288284

@@ -310,7 +306,7 @@ func (c *funcContext) typeName(ty types.Type) string {
310306
anonType, ok := c.p.anonTypeMap.At(ty).(*types.TypeName)
311307
if !ok {
312308
c.initArgs(ty) // cause all embedded types to be registered
313-
varName := c.newVariableWithLevel(strings.ToLower(typeKind(ty)[5:])+"Type", true, "")
309+
varName := c.newVariableWithLevel(strings.ToLower(typeKind(ty)[5:])+"Type", true)
314310
anonType = types.NewTypeName(token.NoPos, c.p.Pkg, varName, ty) // fake types.TypeName
315311
c.p.anonTypes = append(c.p.anonTypes, anonType)
316312
c.p.anonTypeMap.Set(ty, anonType)

0 commit comments

Comments
 (0)