Print tag names in type error messages. Closes #834.
This commit is contained in:
parent
4a894dae8e
commit
f8ac788d66
4 changed files with 31 additions and 14 deletions
|
|
@ -143,13 +143,13 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
|||
bind middle::ast_map::map_crate(*crate));
|
||||
time(time_passes, "external crate/lib resolution",
|
||||
bind creader::read_crates(sess, *crate));
|
||||
let d =
|
||||
let {def_map, ext_map} =
|
||||
time(time_passes, "resolution",
|
||||
bind resolve::resolve_crate(sess, ast_map, crate));
|
||||
let freevars =
|
||||
time(time_passes, "freevar finding",
|
||||
bind freevars::annotate_freevars(sess, d, crate));
|
||||
let ty_cx = ty::mk_ctxt(sess, d, ast_map, freevars);
|
||||
bind freevars::annotate_freevars(sess, def_map, crate));
|
||||
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, ast_map, freevars);
|
||||
time::<()>(time_passes, "typechecking",
|
||||
bind typeck::check_crate(ty_cx, crate));
|
||||
time::<()>(time_passes, "alt checking",
|
||||
|
|
@ -222,9 +222,9 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,
|
|||
alt ppm {
|
||||
ppm_typed. {
|
||||
let amap = middle::ast_map::map_crate(*crate);
|
||||
let d = resolve::resolve_crate(sess, amap, crate);
|
||||
let freevars = freevars::annotate_freevars(sess, d, crate);
|
||||
let ty_cx = ty::mk_ctxt(sess, d, amap, freevars);
|
||||
let {def_map, ext_map} = resolve::resolve_crate(sess, amap, crate);
|
||||
let freevars = freevars::annotate_freevars(sess, def_map, crate);
|
||||
let ty_cx = ty::mk_ctxt(sess, def_map, ext_map, amap, freevars);
|
||||
typeck::check_crate(ty_cx, crate);
|
||||
ann = {pre: ann_paren_for_expr, post: bind ann_typed_post(ty_cx, _)};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import syntax::print::pprust::*;
|
|||
|
||||
export resolve_crate;
|
||||
export def_map;
|
||||
export ext_map;
|
||||
|
||||
// Resolving happens in two passes. The first pass collects defids of all
|
||||
// (internal) imports and modules, so that they can be looked up when needed,
|
||||
|
|
@ -113,6 +114,7 @@ type indexed_mod =
|
|||
only need to look at them to determine exports, which they can't control.*/
|
||||
|
||||
type def_map = hashmap<node_id, def>;
|
||||
type ext_map = hashmap<def_id, [ident]>;
|
||||
|
||||
type env =
|
||||
{cstore: cstore::cstore,
|
||||
|
|
@ -133,7 +135,7 @@ tag dir { inside; outside; }
|
|||
tag namespace { ns_value; ns_type; ns_module; }
|
||||
|
||||
fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
|
||||
def_map {
|
||||
{def_map: def_map, ext_map: ext_map} {
|
||||
let e =
|
||||
@{cstore: sess.get_cstore(),
|
||||
def_map: new_int_hash::<def>(),
|
||||
|
|
@ -148,7 +150,7 @@ fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) ->
|
|||
resolve_imports(*e);
|
||||
check_for_collisions(e, *crate);
|
||||
resolve_names(e, crate);
|
||||
ret e.def_map;
|
||||
ret {def_map: e.def_map, ext_map: e.ext_map};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -212,6 +212,9 @@ type ctxt =
|
|||
@{ts: @type_store,
|
||||
sess: session::session,
|
||||
def_map: resolve::def_map,
|
||||
// We need the ext_map just for printing the types of tags defined in
|
||||
// other crates. Once we get cnames back it should go.
|
||||
ext_map: resolve::ext_map,
|
||||
node_types: node_type_table,
|
||||
items: ast_map::map,
|
||||
freevars: freevars::freevar_map,
|
||||
|
|
@ -392,7 +395,8 @@ fn mk_rcache() -> creader_cache {
|
|||
}
|
||||
|
||||
|
||||
fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
|
||||
fn mk_ctxt(s: session::session, dm: resolve::def_map,
|
||||
em: hashmap<def_id, [ident]>, amap: ast_map::map,
|
||||
freevars: freevars::freevar_map) -> ctxt {
|
||||
let ntt: node_type_table =
|
||||
@smallintmap::mk::<ty::ty_param_substs_opt_and_ty>();
|
||||
|
|
@ -402,6 +406,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
|
|||
@{ts: ts,
|
||||
sess: s,
|
||||
def_map: dm,
|
||||
ext_map: em,
|
||||
node_types: ntt,
|
||||
items: amap,
|
||||
freevars: freevars,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import pp::zerobreak;
|
|||
import pp::hardbreak;
|
||||
import ast::ty_mach_to_str;
|
||||
import syntax::ast;
|
||||
import middle::ast_map;
|
||||
import metadata::csearch;
|
||||
|
||||
fn mode_str(m: &ty::mode) -> str {
|
||||
alt m {
|
||||
|
|
@ -35,6 +37,17 @@ fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str {
|
|||
ret alt i { none. { "anon" + int::str(id) } some(s) { s } };
|
||||
}
|
||||
|
||||
fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str {
|
||||
if (id.crate != ast::local_crate) {
|
||||
str::connect(cx.ext_map.get(id), "::")
|
||||
} else {
|
||||
alt cx.items.find(id.node) {
|
||||
some(ast_map::node_item(it)) { it.ident }
|
||||
_ { fail "get_id_ident: can't find item in ast_map" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
||||
fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) ->
|
||||
str {
|
||||
|
|
@ -105,9 +118,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
|||
s += "(" + str::connect(strs, ",") + ")";
|
||||
}
|
||||
ty_tag(id, tps) {
|
||||
// The user should never see this if the cname is set properly!
|
||||
|
||||
s += "<tag#" + int::str(id.crate) + ":" + int::str(id.node) + ">";
|
||||
s += get_id_ident(cx, id);
|
||||
if vec::len::<t>(tps) > 0u {
|
||||
let strs: [str] = ~[];
|
||||
for typ: t in tps { strs += ~[ty_to_str(cx, typ)]; }
|
||||
|
|
@ -128,8 +139,7 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str {
|
|||
s += "obj {\n\t" + str::connect(strs, "\n\t") + "\n}";
|
||||
}
|
||||
ty_res(id, _, _) {
|
||||
s +=
|
||||
"<resource#" + int::str(id.node) + ":" + int::str(id.crate) + ">";
|
||||
s += get_id_ident(cx, id);
|
||||
}
|
||||
ty_var(v) { s += "<T" + int::str(v) + ">"; }
|
||||
ty_param(id,_) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue