From dbdd08112e9b02ad07e2db13890c1a51b4857bac Mon Sep 17 00:00:00 2001 From: Alexey Derlaft Date: Thu, 25 Feb 2016 11:41:59 +0300 Subject: [PATCH] scope.IndirectValue() and nil pointer This is (patrial) solution for bug qor/qor#161. I can still reproduce it (in creation form), but this may be a qor issue. --- scope.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scope.go b/scope.go index a11d4ec4..e4008ffa 100644 --- a/scope.go +++ b/scope.go @@ -28,7 +28,11 @@ func (scope *Scope) IndirectValue() reflect.Value { if scope.indirectValue == nil { value := reflect.Indirect(reflect.ValueOf(scope.Value)) if value.Kind() == reflect.Ptr { - value = value.Elem() + if !value.IsNil() { + value = reflect.Indirect(value) + } else { + value.Set(reflect.New(value.Type().Elem())) + } } scope.indirectValue = &value }