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 1fe7507

Browse filesBrowse files
committed
Second struct in type revel fails to find the controller revel#730
revel#730 Signed-off-by: NotZippy <notzippy@gmail.com>
1 parent 8ae827e commit 1fe7507
Copy full SHA for 1fe7507

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
@@ -205,10 +205,10 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
205205

206206
if scanControllers {
207207
// Match and add both structs and methods
208-
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports)
208+
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset)
209209
appendAction(fset, methodSpecs, decl, pkgImportPath, pkg.Name, imports)
210210
} else if scanTests {
211-
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports)
211+
structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset)
212212
}
213213

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

303303
// If this Decl is a struct type definition, it is summarized and added to specs.
304304
// Else, specs is returned unchanged.
305-
func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, decl ast.Decl, imports map[string]string) []*TypeInfo {
305+
func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, decl ast.Decl, imports map[string]string, fset *token.FileSet) []*TypeInfo {
306306
// Filter out non-Struct type declarations.
307-
spec, found := getStructTypeDecl(decl)
307+
spec, found := getStructTypeDecl(decl, fset)
308308
if !found {
309309
return specs
310310
}
@@ -350,7 +350,6 @@ func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, dec
350350
return pkgIdent.Name, selectorExpr.Sel.Name
351351
}
352352
}
353-
354353
return "", ""
355354
}()
356355

@@ -607,7 +606,7 @@ func (s *embeddedTypeName) String() string {
607606

608607
// getStructTypeDecl checks if the given decl is a type declaration for a
609608
// struct. If so, the TypeSpec is returned.
610-
func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
609+
func getStructTypeDecl(decl ast.Decl, fset *token.FileSet) (spec *ast.TypeSpec, found bool) {
611610
genDecl, ok := decl.(*ast.GenDecl)
612611
if !ok {
613612
return
@@ -617,15 +616,13 @@ func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
617616
return
618617
}
619618

620-
if len(genDecl.Specs) != 1 {
621-
revel.TRACE.Printf("Surprising: Decl does not have 1 Spec: %v", genDecl)
619+
if len(genDecl.Specs) == 0 {
620+
revel.WARN.Printf("Surprising: %s:%d Decl contains no specifications", fset.Position(decl.Pos()).Filename, fset.Position(decl.Pos()).Line)
622621
return
623622
}
624623

625624
spec = genDecl.Specs[0].(*ast.TypeSpec)
626-
if _, ok := spec.Type.(*ast.StructType); ok {
627-
found = true
628-
}
625+
_, found = spec.Type.(*ast.StructType)
629626

630627
return
631628
}

0 commit comments

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