Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isNil() 问题 #54

Open
keroro6 opened this issue Aug 18, 2022 · 0 comments
Open

isNil() 问题 #54

keroro6 opened this issue Aug 18, 2022 · 0 comments

Comments

@keroro6
Copy link

keroro6 commented Aug 18, 2022

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 不能搭配 || && 使用吗

@keroro6 keroro6 closed this as completed Aug 18, 2022
@keroro6 keroro6 reopened this Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant