engine, lang: Allow resources with a field of type interface
This lets us add a resource that has an implementation with a field whose type is determined at compile time. This let's us write more flexible resources. What's missing is additional type checking so that we guarantee that a specific resource doesn't change types during run-time.
This commit is contained in:
@@ -98,6 +98,7 @@ func ResTypeOf(t reflect.Type) (*Type, error) {
|
||||
StructTagOpt(StructTag),
|
||||
StrictStructTagOpt(true),
|
||||
SkipBadStructFieldsOpt(true),
|
||||
AllowInterfaceTypeOpt(true),
|
||||
}
|
||||
return ConfigurableTypeOf(t, opts...)
|
||||
}
|
||||
|
||||
@@ -283,6 +283,15 @@ func Into(v Value, rv reflect.Value) error {
|
||||
if typ == nil {
|
||||
return fmt.Errorf("cannot Into() %+v of type %s into a nil type", v, v.Type())
|
||||
}
|
||||
// This is used when we are setting a resource field which has type of
|
||||
// interface{} instead of a string, bool, list, etc...
|
||||
if isInterface := typ.Kind() == reflect.Interface; isInterface {
|
||||
//x := reflect.ValueOf(v) // no!
|
||||
// use the value with type interface{}, not types.Value
|
||||
x := reflect.ValueOf(v.Value())
|
||||
rv.Set(x)
|
||||
return nil
|
||||
}
|
||||
|
||||
switch v := v.(type) {
|
||||
case *BoolValue:
|
||||
|
||||
Reference in New Issue
Block a user