Skip to content

Commit

Permalink
Fix handling of anonymous types within imported packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsf committed Dec 11, 2012
1 parent 1a1e92e commit 865acbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion decl.go
Expand Up @@ -384,8 +384,10 @@ func (d *decl) pretty_print_type(out io.Writer) {
case decl_type:
switch d.typ.(type) {
case *ast.StructType:
// TODO: not used due to anonymify?
fmt.Fprintf(out, "struct")
case *ast.InterfaceType:
// TODO: not used due to anonymify?
fmt.Fprintf(out, "interface")
default:
if d.typ != nil {
Expand Down Expand Up @@ -994,7 +996,10 @@ func pretty_print_type_expr(out io.Writer, e ast.Expr) {
case 's':
fmt.Fprintf(out, "struct")
case 'i':
fmt.Fprintf(out, "interface")
// ok, in most cases anonymous interface is an
// empty interface, I'll just pretend that
// it's always true
fmt.Fprintf(out, "interface{}")
}
} else {
fmt.Fprintf(out, t.Name)
Expand Down
11 changes: 6 additions & 5 deletions package.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"errors"
"strings"
"fmt"
"go/ast"
"go/token"
Expand Down Expand Up @@ -118,6 +119,7 @@ func (m *package_file_cache) process_package_data(data []byte) {
// create map for other packages
m.others = make(map[string]*decl)
p.parse_export(func(pkg string, decl ast.Decl) {
anonymify_ast(decl, decl_foreign, m.scope)
if pkg == "" {
// main package
add_ast_decl_to_package(m.main, decl, m.scope)
Expand All @@ -135,6 +137,9 @@ func (m *package_file_cache) process_package_data(data []byte) {

// WTF is that? :D
for key, value := range m.scope.entities {
if strings.HasPrefix(key, "$") {
continue
}
pkg, ok := m.others[value.name]
if !ok && value.name == m.name {
pkg = m.main
Expand Down Expand Up @@ -420,7 +425,7 @@ func (p *gc_parser) parse_parameter() *ast.Field {
// Parameters = "(" [ ParameterList ] ")" .
// ParameterList = { Parameter "," } Parameter .
func (p *gc_parser) parse_parameters() *ast.FieldList {
var flds []*ast.Field
flds := []*ast.Field{}
parse_parameter := func() {
par := p.parse_parameter()
flds = append(flds, par)
Expand All @@ -435,10 +440,6 @@ func (p *gc_parser) parse_parameters() *ast.FieldList {
}
}
p.expect(')')

if flds == nil {
return nil
}
return &ast.FieldList{List: flds}
}

Expand Down

0 comments on commit 865acbb

Please sign in to comment.