@@ -1348,16 +1348,29 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
13481348 // typeof(v) isa DataType, so v is an *instance of* a type that is a Datatype,
13491349 // meaning v is e.g. an instance of a struct. These are printed as a call to a
13501350 // type constructor, such as e.g. `Base.UnitRange{Int64}(start=1, stop=2)`
1351+
13511352 int istuple = jl_is_tuple_type (vt ), isnamedtuple = jl_is_namedtuple_type (vt );
1353+ int isprimitivetype = jl_is_primitivetype (vt );
1354+
1355+ // In many cases, default constructors may not be available (e.g. primitive types
1356+ // never have them), so print these as "reinterpret(Foo, ...)" to make sure that
1357+ // these round-trip as expected.
1358+ int reinterpret = isprimitivetype ;
1359+
13521360 size_t tlen = jl_datatype_nfields (vt );
1361+ if (reinterpret )
1362+ n += jl_printf (out , "reinterpret(" );
13531363 if (isnamedtuple ) {
13541364 if (tlen == 0 )
13551365 n += jl_printf (out , "NamedTuple" );
13561366 }
13571367 else if (!istuple ) {
13581368 n += jl_static_show_x (out , (jl_value_t * )vt , depth , ctx );
13591369 }
1360- n += jl_printf (out , "(" );
1370+ if (reinterpret )
1371+ n += jl_printf (out , ", " );
1372+ if (!isprimitivetype )
1373+ n += jl_printf (out , "(" );
13611374 size_t nb = jl_datatype_size (vt );
13621375 if (nb > 0 && tlen == 0 ) {
13631376 uint8_t * data = (uint8_t * )v ;
@@ -1405,7 +1418,10 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
14051418 n += jl_static_show_next_ (out , next , v , depth , ctx );
14061419 }
14071420 }
1408- n += jl_printf (out , ")" );
1421+ if (!isprimitivetype )
1422+ n += jl_printf (out , ")" );
1423+ if (reinterpret )
1424+ n += jl_printf (out , ")" );
14091425 }
14101426 else {
14111427 n += jl_printf (out , "<?#%p::" , (void * )v );
0 commit comments