@@ -409,56 +409,66 @@ static void type__add(
409409
410410 return ;
411411 }
412- else if (!ti_val_is_str (query -> rval ))
413- {
414- ex_set (e , EX_TYPE_ERROR ,
415- "function `%s` expects argument 4 to be of "
416- "type `" TI_VAL_STR_S "` or type `" TI_VAL_CLOSURE_S "` "
417- "but got type `%s` instead" DOC_MOD_TYPE_ADD ,
418- fnname , ti_val_str (query -> rval ));
412+
413+ spec_raw = ti_type_nested_from_val (type , query -> rval , e );
414+ if (e -> nr )
419415 return ;
420- }
421416
422- spec_raw = (ti_raw_t * ) query -> rval ;
423- if (spec_raw -> n == 1 && spec_raw -> data [0 ] == '#' )
417+ if (spec_raw )
418+ ti_val_unsafe_gc_drop (query -> rval );
419+ else
424420 {
425- if (nargs == 5 )
421+ if (! ti_val_is_str ( query -> rval ) )
426422 {
427- ex_set (e , EX_NUM_ARGUMENTS ,
428- "function `%s` takes at most 4 arguments when adding "
429- "an Id ('#') definition" DOC_MOD_TYPE_ADD ,
430- fnname );
423+ ex_set (e , EX_TYPE_ERROR ,
424+ "function `%s` expects argument 4 to be of "
425+ "type `" TI_VAL_STR_S "` or type `" TI_VAL_CLOSURE_S "` "
426+ "but got type `%s` instead" DOC_MOD_TYPE_ADD ,
427+ fnname , ti_val_str (query -> rval ));
431428 return ;
432429 }
430+ spec_raw = (ti_raw_t * ) query -> rval ;
433431
434- if (type -> idname )
432+ if (spec_raw -> n == 1 && spec_raw -> data [ 0 ] == '#' )
435433 {
436- ex_set (e , EX_LOOKUP_ERROR ,
437- "multiple Id ('#') definitions on type `%s`" ,
438- type -> name );
439- return ;
440- }
434+ if (nargs == 5 )
435+ {
436+ ex_set (e , EX_NUM_ARGUMENTS ,
437+ "function `%s` takes at most 4 arguments when adding "
438+ "an Id ('#') definition" DOC_MOD_TYPE_ADD ,
439+ fnname );
440+ return ;
441+ }
441442
442- task = ti_task_get_task (query -> change , query -> collection -> root );
443- if (!task )
444- {
445- ex_set_mem (e );
446- return ;
447- }
443+ if (type -> idname )
444+ {
445+ ex_set (e , EX_LOOKUP_ERROR ,
446+ "multiple Id ('#') definitions on type `%s`" ,
447+ type -> name );
448+ return ;
449+ }
450+
451+ task = ti_task_get_task (query -> change , query -> collection -> root );
452+ if (!task )
453+ {
454+ ex_set_mem (e );
455+ return ;
456+ }
448457
449- /* update modified time-stamp */
450- type -> modified_at = util_now_usec ();
451- type -> idname = name ;
452- ti_incref (name );
458+ /* update modified time-stamp */
459+ type -> modified_at = util_now_usec ();
460+ type -> idname = name ;
461+ ti_incref (name );
453462
454- if (ti_task_add_mod_type_add_idname (task , type ))
455- {
456- /* modified is wrong; the rest we can revert */
457- type -> idname = NULL ;
458- ti_decref (name );
459- ex_set_mem (e );
463+ if (ti_task_add_mod_type_add_idname (task , type ))
464+ {
465+ /* modified is wrong; the rest we can revert */
466+ type -> idname = NULL ;
467+ ti_decref (name );
468+ ex_set_mem (e );
469+ }
470+ return ;
460471 }
461- return ;
462472 }
463473
464474 query -> rval = NULL ;
@@ -857,7 +867,7 @@ static void type__mod(
857867 const int nargs = fn_get_nargs (nd );
858868 ti_field_t * field = ti_field_by_name (type , name );
859869 ti_method_t * method = field ? NULL : ti_type_get_method (type , name );
860-
870+ ti_raw_t * spec_raw = NULL ;
861871 cleri_node_t * child ;
862872
863873 if (fn_nargs_range (fnname , DOC_MOD_TYPE_MOD , 4 , 5 , nargs , e ))
@@ -935,10 +945,12 @@ static void type__mod(
935945 return ;
936946 }
937947
948+ spec_raw = ti_type_nested_from_val (type , query -> rval , e );
949+ if (e -> nr )
950+ return ;
951+
938952 if (ti_val_is_str (query -> rval ))
939953 {
940- ti_raw_t * spec_raw ;
941-
942954 if (!field )
943955 {
944956 ex_set (e , EX_TYPE_ERROR ,
@@ -956,7 +968,10 @@ static void type__mod(
956968 }
957969
958970 query -> rval = NULL ;
971+ }
959972
973+ if (spec_raw )
974+ {
960975 if (nargs == 4 )
961976 {
962977 ti_task_t * task ;
@@ -1453,7 +1468,7 @@ static void type__wpo(
14531468 if (wrap_only && ti_type_required_by_non_wpo (type , e ))
14541469 return ;
14551470
1456- if (!wrap_only && ti_type_uses_wpo (type , e ))
1471+ if (!wrap_only && ti_type_requires_wpo (type , e ))
14571472 return ;
14581473
14591474 task = ti_task_get_task (query -> change , query -> collection -> root );
0 commit comments