From 551eb48c5899d50f5e56efc050fdb1a5a9114322 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Fri, 7 Jun 2024 09:01:33 +1000 Subject: [PATCH] fix: crash using nil ref pointer (#1688) 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 --- go-runtime/compile/schema.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/go-runtime/compile/schema.go b/go-runtime/compile/schema.go index 69421de57f..b71a2e67d7 100644 --- a/go-runtime/compile/schema.go +++ b/go-runtime/compile/schema.go @@ -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 { @@ -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 }