Просмотр исходного кода

internal/impl: fix SetLazyValue

Since the internal body calls ExtensionType.ValueOf, it seems that the
intent is for lazyExtensionValue.value to store a:
	func() protoreflect.Value
instead of a:
	func() interface{}

This seems more apparent given that GetValue returns a pref.Value.

Change-Id: I1679fe56088c20d5c8d36360e75dd773850da4c2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/193757
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai 6 лет назад
Родитель
Сommit
8ee364e4bf
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      internal/impl/codec_extension.go

+ 2 - 2
internal/impl/codec_extension.go

@@ -137,7 +137,7 @@ func (f *ExtensionField) SetEagerValue(ival interface{}) {
 
 // Deprecated: Do not use.
 func (f *ExtensionField) SetLazyValue(fn func() interface{}) {
-	f.lazy = &lazyExtensionValue{value: func() interface{} {
+	f.lazy = &lazyExtensionValue{value: func() pref.Value {
 		return f.typ.ValueOf(fn())
 	}}
 }
@@ -145,7 +145,7 @@ func (f *ExtensionField) SetLazyValue(fn func() interface{}) {
 type lazyExtensionValue struct {
 	once  uint32      // atomically set if value is valid
 	mu    sync.Mutex  // protects value
-	value interface{} // either the value itself or a func() interface{}
+	value interface{} // either a pref.Value itself or a func() pref.ValueOf
 }
 
 func (v *lazyExtensionValue) GetValue() pref.Value {