Skip to content

Commit 438f9cb

Browse files
authored
Core printing: improve show of methods (#39135)
This adds their environment, so that their TypeVars will print correctly.
1 parent 6cff73f commit 438f9cb

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/rtutils.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,55 +1199,71 @@ JL_DLLEXPORT size_t jl_static_show(JL_STREAM *out, jl_value_t *v) JL_NOTSAFEPOIN
11991199

12001200
JL_DLLEXPORT size_t jl_static_show_func_sig(JL_STREAM *s, jl_value_t *type) JL_NOTSAFEPOINT
12011201
{
1202+
size_t n = 0;
1203+
size_t i;
12021204
jl_value_t *ftype = (jl_value_t*)jl_first_argument_datatype(type);
12031205
if (ftype == NULL)
12041206
return jl_static_show(s, type);
1205-
size_t n = 0;
1207+
jl_unionall_t *tvars = (jl_unionall_t*)type;
1208+
int nvars = jl_subtype_env_size(type);
1209+
struct recur_list *depth = NULL;
1210+
if (nvars > 0) {
1211+
depth = (struct recur_list*)alloca(sizeof(struct recur_list) * nvars);
1212+
for (i = 0; i < nvars; i++) {
1213+
depth[i].prev = i == 0 ? NULL : &depth[i - 1];
1214+
depth[i].v = type;
1215+
type = ((jl_unionall_t*)type)->body;
1216+
}
1217+
depth += nvars - 1;
1218+
}
1219+
if (!jl_is_datatype(type)) {
1220+
n += jl_static_show(s, type);
1221+
return n;
1222+
}
12061223
if (jl_nparams(ftype) == 0 || ftype == ((jl_datatype_t*)ftype)->name->wrapper) {
12071224
n += jl_printf(s, "%s", jl_symbol_name(((jl_datatype_t*)ftype)->name->mt->name));
12081225
}
12091226
else {
12101227
n += jl_printf(s, "(::");
1211-
n += jl_static_show(s, ftype);
1228+
n += jl_static_show_x(s, ftype, depth);
12121229
n += jl_printf(s, ")");
12131230
}
1214-
jl_unionall_t *tvars = (jl_unionall_t*)type;
1215-
type = jl_unwrap_unionall(type);
1216-
if (!jl_is_datatype(type)) {
1217-
n += jl_printf(s, " ");
1218-
n += jl_static_show(s, type);
1219-
return n;
1220-
}
12211231
size_t tl = jl_nparams(type);
12221232
n += jl_printf(s, "(");
1223-
size_t i;
12241233
for (i = 1; i < tl; i++) {
12251234
jl_value_t *tp = jl_tparam(type, i);
12261235
if (i != tl - 1) {
1227-
n += jl_static_show(s, tp);
1236+
n += jl_static_show_x(s, tp, depth);
12281237
n += jl_printf(s, ", ");
12291238
}
12301239
else {
1231-
if (jl_is_vararg(tp)) {
1232-
n += jl_static_show(s, jl_unwrap_vararg(tp));
1240+
if (jl_vararg_kind(tp) == JL_VARARG_UNBOUND) {
1241+
tp = jl_unwrap_vararg(tp);
1242+
if (jl_is_unionall(tp))
1243+
n += jl_printf(s, "(");
1244+
n += jl_static_show_x(s, tp, depth);
1245+
if (jl_is_unionall(tp))
1246+
n += jl_printf(s, ")");
12331247
n += jl_printf(s, "...");
12341248
}
12351249
else {
1236-
n += jl_static_show(s, tp);
1250+
n += jl_static_show_x(s, tp, depth);
12371251
}
12381252
}
12391253
}
12401254
n += jl_printf(s, ")");
12411255
if (jl_is_unionall(tvars)) {
1256+
depth -= nvars - 1;
12421257
int first = 1;
12431258
n += jl_printf(s, " where {");
12441259
while (jl_is_unionall(tvars)) {
1245-
if (first)
1246-
first = 0;
1247-
else
1260+
if (!first)
12481261
n += jl_printf(s, ", ");
1249-
n += jl_static_show(s, (jl_value_t*)tvars->var);
1262+
n += jl_static_show_x(s, (jl_value_t*)tvars->var, first ? NULL : depth);
12501263
tvars = (jl_unionall_t*)tvars->body;
1264+
if (!first)
1265+
depth += 1;
1266+
first = 0;
12511267
}
12521268
n += jl_printf(s, "}");
12531269
}

0 commit comments

Comments
 (0)