Skip to content

Instantly share code, notes, and snippets.

@cygx

cygx/Bug.pm6 Secret

Created October 8, 2016 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cygx/9c9fa30c43967512b8c228f3bcc31bb1 to your computer and use it in GitHub Desktop.
Save cygx/9c9fa30c43967512b8c228f3bcc31bb1 to your computer and use it in GitHub Desktop.
Rakudo bug
my role IO { ... }
my class IO::VMHandle is repr<MVMOSHandle> { method new {} }
my role IO {}
# IO::<VMHandle> := IO::VMHandle;
sub EXPORT { Map.new((IO => IO)) }
$ perl6 -I. -MBug -e 'say IO::VMHandle.^name; IO::VMHandle.new'
NQPMu
# uncomment line in Bug.pm6
$ perl6 -I. -MBug -e 'say IO::VMHandle.^name; IO::VMHandle.new'
IO::VMHandle
Internal error: inconsistent bind result
in method new at D:\dev\p6\newio\Bug.pm (Bug) line 2
in block <unit> at -e line 1
diff --git a/src/6model/reprs/MVMOSHandle.c b/src/6model/reprs/MVMOSHandle.c
index fe24d4d..284af9f 100644
--- a/src/6model/reprs/MVMOSHandle.c
+++ b/src/6model/reprs/MVMOSHandle.c
@@ -68,6 +68,27 @@ static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *
return &storage_spec;
}
+/* Performs a change of type, where possible. */
+static void change_type(MVMThreadContext *tc, MVMObject *obj, MVMObject *new_type) {
+ /* Ensure we don't have a type object. */
+ if (!IS_CONCRETE(obj))
+ MVM_exception_throw_adhoc(tc,
+ "Cannot change the type of a type object");
+
+ /* Ensure that the REPR of the new type is also MVMOSHandle. */
+ if (REPR(new_type)->ID != REPR(obj)->ID)
+ MVM_exception_throw_adhoc(tc,
+ "New type must have a matching representation");
+
+ /* Switch over the STable. */
+ MVM_ASSIGN_REF(tc, &(obj->header), obj->st, STABLE(new_type));
+}
+
+/* Set the size of the STable. */
+static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
+ st->size = sizeof(MVMOSHandle);
+}
+
/* Compose the representation. */
static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) {
/* Nothing to do for this REPR. */
@@ -89,12 +110,12 @@ static const MVMREPROps this_repr = {
MVM_REPR_DEFAULT_ASS_FUNCS,
MVM_REPR_DEFAULT_ELEMS,
get_storage_spec,
- NULL, /* change_type */
+ change_type,
NULL, /* serialize */
NULL, /* deserialize */
NULL, /* serialize_repr_data */
NULL, /* deserialize_repr_data */
- NULL, /* deserialize_stable_size */
+ deserialize_stable_size,
gc_mark,
gc_free,
NULL, /* gc_cleanup */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment