Skip to content

Commit

Permalink
fix: crash using nil ref pointer (#1688)
Browse files Browse the repository at this point in the history
I was getting a crash when doing this:
`ftl build go-runtime/compile/testdata`
We were returning a nil pointer but then didn't check for nil
  • Loading branch information
matt2e authored Jun 6, 2024
1 parent f8149b6 commit 551eb48
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ func parseCall(pctx *parseContext, node *ast.CallExpr, stack []ast.Node) {
}
ref := parseVerbRef(pctx, node.Args[1])
if ref == nil {
ref = parseSelectorRef(node.Args[1])
var suffix string
if pctx.schema.Resolve(ref).Ok() {
var ok bool
ref, ok = parseSelectorRef(node.Args[1])
if ok && pctx.schema.Resolve(ref).Ok() {
suffix = ", does it need to be exported?"
}
if sel, ok := node.Args[1].(*ast.SelectorExpr); ok {
Expand All @@ -441,20 +442,20 @@ func parseCall(pctx *parseContext, node *ast.CallExpr, stack []ast.Node) {
activeVerb.AddCall(ref)
}

func parseSelectorRef(node ast.Expr) *schema.Ref {
func parseSelectorRef(node ast.Expr) (*schema.Ref, bool) {
sel, ok := node.(*ast.SelectorExpr)
if !ok {
return nil
return nil, false
}
ident, ok := sel.X.(*ast.Ident)
if !ok {
return nil
return nil, false
}
return &schema.Ref{
Pos: goPosToSchemaPos(node.Pos()),
Module: ident.Name,
Name: strcase.ToLowerCamel(sel.Sel.Name),
}
}, true

}

Expand Down

0 comments on commit 551eb48

Please sign in to comment.