Permalink
Browse files

Fix handling of anonymous types within imported packages.

  • Loading branch information...
1 parent 1a1e92e commit 865acbb9c8b8a046aa2996de0a230a4b4a3913ac @nsf committed Dec 11, 2012
Showing with 12 additions and 6 deletions.
  1. +6 −1 decl.go
  2. +6 −5 package.go
View
@@ -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 {
@@ -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)
View
@@ -3,6 +3,7 @@ package main
import (
"bytes"
"errors"
+ "strings"
"fmt"
"go/ast"
"go/token"
@@ -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)
@@ -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
@@ -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)
@@ -435,10 +440,6 @@ func (p *gc_parser) parse_parameters() *ast.FieldList {
}
}
p.expect(')')
-
- if flds == nil {
- return nil
- }
return &ast.FieldList{List: flds}
}

0 comments on commit 865acbb

Please sign in to comment.