Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d07d810

Browse filesBrowse files
committed
Merge pull request revel#731 from notzippy/issue-730
Second struct in type revel fails to find the controller revel#730
2 parents aaf3141 + 1fe7507 commit d07d810
Copy full SHA for d07d810

File tree

Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed

‎harness/reflect.go

Copy file name to clipboardExpand all lines: harness/reflect.go
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
212212

213213
if scanControllers {
214214
// Match and add both structs and methods
215-
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports)
215+
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset)
216216
appendAction(fset, methodSpecs, decl, pkgImportPath, pkg.Name, imports)
217217
} else if scanTests {
218-
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports)
218+
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset)
219219
}
220220

221221
// If this is a func...
@@ -309,9 +309,9 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
309309

310310
// If this Decl is a struct type definition, it is summarized and added to specs.
311311
// Else, specs is returned unchanged.
312-
func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, decl ast.Decl, imports map[string]string) []*TypeInfo {
312+
func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, decl ast.Decl, imports map[string]string, fset *token.FileSet) []*TypeInfo {
313313
// Filter out non-Struct type declarations.
314-
spec, found := getStructTypeDecl(decl)
314+
spec, found := getStructTypeDecl(decl, fset)
315315
if !found {
316316
return specs
317317
}
@@ -357,7 +357,6 @@ func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, dec
357357
return pkgIdent.Name, selectorExpr.Sel.Name
358358
}
359359
}
360-
361360
return "", ""
362361
}()
363362

@@ -614,7 +613,7 @@ func (s *embeddedTypeName) String() string {
614613

615614
// getStructTypeDecl checks if the given decl is a type declaration for a
616615
// struct. If so, the TypeSpec is returned.
617-
func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
616+
func getStructTypeDecl(decl ast.Decl, fset *token.FileSet) (spec *ast.TypeSpec, found bool) {
618617
genDecl, ok := decl.(*ast.GenDecl)
619618
if !ok {
620619
return
@@ -624,15 +623,13 @@ func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
624623
return
625624
}
626625

627-
if len(genDecl.Specs) != 1 {
628-
revel.TRACE.Printf("Surprising: Decl does not have 1 Spec: %v", genDecl)
626+
if len(genDecl.Specs) == 0 {
627+
revel.WARN.Printf("Surprising: %s:%d Decl contains no specifications", fset.Position(decl.Pos()).Filename, fset.Position(decl.Pos()).Line)
629628
return
630629
}
631630

632631
spec = genDecl.Specs[0].(*ast.TypeSpec)
633-
if _, ok := spec.Type.(*ast.StructType); ok {
634-
found = true
635-
}
632+
_, found = spec.Type.(*ast.StructType)
636633

637634
return
638635
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.