Sanity checks against future reflect package changes to the type or semantics of the Value.flag field.
()
| 104 | // Sanity checks against future reflect package changes |
| 105 | // to the type or semantics of the Value.flag field. |
| 106 | func init() { |
| 107 | field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") |
| 108 | if !ok { |
| 109 | panic("reflect.Value has no flag field") |
| 110 | } |
| 111 | if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { |
| 112 | panic("reflect.Value flag field has changed kind") |
| 113 | } |
| 114 | type t0 int |
| 115 | var t struct { |
| 116 | A t0 |
| 117 | // t0 will have flagEmbedRO set. |
| 118 | t0 |
| 119 | // a will have flagStickyRO set |
| 120 | a t0 |
| 121 | } |
| 122 | vA := reflect.ValueOf(t).FieldByName("A") |
| 123 | va := reflect.ValueOf(t).FieldByName("a") |
| 124 | vt0 := reflect.ValueOf(t).FieldByName("t0") |
| 125 | |
| 126 | // Infer flagRO from the difference between the flags |
| 127 | // for the (otherwise identical) fields in t. |
| 128 | flagPublic := *flagField(&vA) |
| 129 | flagWithRO := *flagField(&va) | *flagField(&vt0) |
| 130 | flagRO = flagPublic ^ flagWithRO |
| 131 | |
| 132 | // Infer flagAddr from the difference between a value |
| 133 | // taken from a pointer and not. |
| 134 | vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") |
| 135 | flagNoPtr := *flagField(&vA) |
| 136 | flagPtr := *flagField(&vPtrA) |
| 137 | flagAddr = flagNoPtr ^ flagPtr |
| 138 | |
| 139 | // Check that the inferred flags tally with one of the known versions. |
| 140 | for _, f := range okFlags { |
| 141 | if flagRO == f.ro && flagAddr == f.addr { |
| 142 | return |
| 143 | } |
| 144 | } |
| 145 | panic("reflect.Value read-only flag has changed semantics") |
| 146 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…