在第一个代码示例中,我收到"if pr!= nil"行的错误:
for sup, _ := range supervisorToColor {
pr := emailToPerson[sup]
// The line below causes the compilation error:
// ./myprog.go:1046: missing condition in if statement
// ./myprog.go:1046: pr != nil evaluated but not used
if pr != nil
{
local := peopleOnFloor[pr.Email]
sp := &Super{pr, local}
names = append(names, sp)
}
}
Run Code Online (Sandbox Code Playgroud)
如果我注释掉nil check if语句,它编译好:
for sup, _ := range supervisorToColor {
pr := emailToPerson[sup]
// if pr != nil
// {
local := peopleOnFloor[pr.Email]
sp := …Run Code Online (Sandbox Code Playgroud) go ×1