@@ -66,8 +66,8 @@ var durationType = reflect.TypeOf(time.Duration(0))
66
66
67
67
// Decode decodes the next value according to the expected type.
68
68
func (d * decoder ) Decode (typ reflect.Type ) (res * reflect.Value , err error ) {
69
- res , isUnmarshaled , err := d .maybeUnmarshal (typ )
70
- if isUnmarshaled {
69
+ res , isUnmarshalled , err := d .maybeUnmarshal (typ )
70
+ if isUnmarshalled {
71
71
return res , err
72
72
}
73
73
switch typ .Kind () {
@@ -145,7 +145,7 @@ func (d *decoder) decodePointer(inType reflect.Type) (*reflect.Value, error) {
145
145
}
146
146
147
147
// maybeUnmarshal determines if typ implements encoding.BinaryUnmarshaler, and if it does,
148
- // performs the unmarshaling .
148
+ // performs the unmarshalling .
149
149
func (d * decoder ) maybeUnmarshal (typ reflect.Type ) (* reflect.Value , bool , error ) {
150
150
ptr := reflect .New (typ )
151
151
unmarshaler , isUnmarshaler := ptr .Interface ().(encoding.BinaryUnmarshaler )
@@ -231,9 +231,9 @@ func (d *decoder) decodePklObject(typ reflect.Type, requireStruct bool) (res *re
231
231
case code == codeRegex :
232
232
res , err = d .decodeRegex ()
233
233
case code == codeClass :
234
- res , err = d .decodeClass ()
234
+ res , err = d .decodeClass (length )
235
235
case code == codeTypeAlias :
236
- res , err = d .decodeTypeAlias ()
236
+ res , err = d .decodeTypeAlias (length )
237
237
default :
238
238
if requireStruct {
239
239
return nil , fmt .Errorf ("code %#02x cannot be decoded into a struct" , code )
@@ -246,7 +246,7 @@ func (d *decoder) decodePklObject(typ reflect.Type, requireStruct bool) (res *re
246
246
if err != nil {
247
247
return nil , err
248
248
}
249
- return res , d .skip (length - getDecodedLength (code ) - 1 ) // -1 is from the code field
249
+ return res , d .skip (length - getDecodedLength (code , length ) - 1 ) // -1 is from the code field
250
250
}
251
251
252
252
// decodeObjectPreamble decodes the preamble for Pkl objects.
@@ -266,7 +266,7 @@ func (d *decoder) decodeObjectPreamble() (int, int, error) {
266
266
}
267
267
268
268
// getDecodedLength returns the number of array fields a specific type code is expected to yield
269
- func getDecodedLength (code int ) int {
269
+ func getDecodedLength (code , length int ) int {
270
270
switch code {
271
271
case codeObject :
272
272
return 3 // name, moduleUri, member array
@@ -277,6 +277,11 @@ func getDecodedLength(code int) int {
277
277
case codeIntSeq :
278
278
return 3 // start, end, step
279
279
case codeClass , codeTypeAlias :
280
+ if length > 1 {
281
+ // pkl 0.30+ includes the qualified name and module uri
282
+ return 2
283
+ }
284
+ // before pkl 0.30 only the type code is present
280
285
return 0
281
286
default :
282
287
return 1
0 commit comments