@@ -57,6 +57,7 @@ use crate::values::StarlarkValue;
57
57
use crate :: values:: StringValue ;
58
58
use crate :: values:: Value ;
59
59
use crate :: values:: ValueLike ;
60
+ use crate :: values:: ValueTyped ;
60
61
use crate :: values:: enumeration:: EnumValue ;
61
62
use crate :: values:: enumeration:: matcher:: EnumTypeMatcher ;
62
63
use crate :: values:: enumeration:: ty_enum_type:: TyEnumData ;
@@ -169,11 +170,14 @@ pub type EnumType<'v> = EnumTypeGen<Value<'v>>;
169
170
pub type FrozenEnumType = EnumTypeGen < FrozenValue > ;
170
171
171
172
impl < ' v > EnumType < ' v > {
172
- pub ( crate ) fn new ( elements : Vec < StringValue < ' v > > , heap : & ' v Heap ) -> crate :: Result < Value < ' v > > {
173
+ pub ( crate ) fn new (
174
+ elements : Vec < StringValue < ' v > > ,
175
+ heap : & ' v Heap ,
176
+ ) -> crate :: Result < ValueTyped < ' v , EnumType < ' v > > > {
173
177
// We are constructing the enum and all elements in one go.
174
178
// They both point at each other, which adds to the complexity.
175
179
let id = TypeInstanceId :: r#gen ( ) ;
176
- let typ = heap. alloc ( EnumType {
180
+ let typ = heap. alloc_typed ( EnumType {
177
181
id,
178
182
ty_enum_data : OnceCell :: new ( ) ,
179
183
elements : UnsafeCell :: new ( SmallMap :: new ( ) ) ,
@@ -183,7 +187,7 @@ impl<'v> EnumType<'v> {
183
187
for ( i, x) in elements. iter ( ) . enumerate ( ) {
184
188
let v = heap. alloc ( EnumValue {
185
189
id,
186
- typ,
190
+ typ : typ . to_value ( ) ,
187
191
index : i as i32 ,
188
192
value : x. to_value ( ) ,
189
193
} ) ;
@@ -195,10 +199,9 @@ impl<'v> EnumType<'v> {
195
199
}
196
200
197
201
// Here we tie the cycle
198
- let t = typ. downcast_ref :: < EnumType > ( ) . unwrap ( ) ;
199
202
unsafe {
200
203
// SAFETY: we own unique reference to `t`.
201
- * t . elements . get ( ) = res;
204
+ * typ . elements . get ( ) = res;
202
205
}
203
206
Ok ( typ)
204
207
}
0 commit comments