isNil() 问题
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 281
- PR merge metrics
- No merged PRs in 30d
Description
const rule2 = `
rule "bot_ask_name" "" salience 12
begin
println("conversation_list")
if ( isNil( BaseData.UserProfile) || BaseData.UserProfile.Name == "") && lastConversationTime(Base, "", "", "10", "70", "") {
return true
}
return false
end
`
base := BaseStartConversation{
ConversationBaseData: ConversationBaseData{
ConversationLogic: *logicObj,
UserId: 9819,
NodeId: 9818,
Node: &httpparams.GetOneRobotNodeResp{
NodeId: 9818,
RobotNodeGeneralProperties: &robotnodedao.RobotNodeGeneralProperties{NickName: "node nick name"},
RobotNodeCharacterProperties: nil,
},
},
}
apis := make(map[string]interface{})
apis["println"] = fmt.Println
apis["index"] = strings.Index
pool, err := engine.NewGenginePool(10, 20, 1, rule1, apis)
data := make(map[string]interface{})
data["BaseData"] = base.ConversationBaseData
data["Base"] = &base
data["println"] = fmt.Println
data["lastConversationTime"] = lastConversationTime
err = pool.UpdatePooledRulesIncremental(rule2)
//lastConversationTime()
t.Log(err)
assert.Assert(t, err == nil)
err, result := pool.ExecuteSelectedRules(data, []string{"bot_ask_name"})
t.Log(err)
assert.Assert(t, err == nil)
t.Log(result)
其中UserProfile是BaseData的一个结构体指针成员, 报错信息如下
conversation_list
--- FAIL: Test_gengine_pool_bot_inform_city_bot_ask_weather (0.08s)
panic: reflect: call of reflect.Value.FieldByName on zero Value [recovered]
panic: reflect: call of reflect.Value.FieldByName on zero Value
这个 我测试了,就是isNil执行完后,虽然命中了条件(BaseData.UserProfile==nil),但是还会继续 || 后面的那个BaseData.UserProfile.Name,访问了空指针,想问下这个执行逻辑是什么?isNil 不能搭配 || && 使用吗
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the supplied Go reproducer and trace evaluation through isNil(), the || expression, and ExecuteSelectedRules. Determine whether the reported nil-pointer access matches the engine's intended short-circuit behavior; done means the behavior is clarified and the reproducer no longer exposes an unexpected panic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100