From 23d7f2913c587e1e729ea08c955ccbbd98d3c995 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 15 Nov 2024 13:55:36 +0800 Subject: [PATCH] refactor(kotlin): update null safety in GoFullIdentListener.kt Avoid potential null pointer exceptions by using safe call operator on typeDef references within the buildTypeSpec function. This change ensures the code is more robust when dealing with optional types. --- .../src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt b/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt index 1b524cf2..823f7be5 100644 --- a/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt +++ b/chapi-ast-go/src/main/kotlin/chapi/ast/goast/GoFullIdentListener.kt @@ -176,7 +176,7 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() { private fun buildTypeSpec(typeSpec: GoParser.TypeSpecContext) { val typeDef = typeSpec.typeDef() val identifyName = typeDef?.IDENTIFIER()?.text ?: "" - typeDef.type_().typeLit()?.let { + typeDef?.type_()?.typeLit()?.let { when (val typeChild = it.getChild(0)) { is GoParser.StructTypeContext -> { buildStruct(identifyName, typeChild)