Add better error messages for duplicate term declarations
This commit is contained in:
committed by
Chris Fallin
parent
22e18a9d98
commit
8f5dffab72
@@ -198,6 +198,8 @@ pub struct TermEnv {
|
|||||||
pub struct Term {
|
pub struct Term {
|
||||||
/// This term's id.
|
/// This term's id.
|
||||||
pub id: TermId,
|
pub id: TermId,
|
||||||
|
/// The source position where this term was declared.
|
||||||
|
pub decl_pos: Pos,
|
||||||
/// The name of this term.
|
/// The name of this term.
|
||||||
pub name: Sym,
|
pub name: Sym,
|
||||||
/// The parameter types to this term.
|
/// The parameter types to this term.
|
||||||
@@ -776,11 +778,15 @@ impl TermEnv {
|
|||||||
&ast::Def::Decl(ref decl) => {
|
&ast::Def::Decl(ref decl) => {
|
||||||
let tid = TermId(self.terms.len());
|
let tid = TermId(self.terms.len());
|
||||||
let name = tyenv.intern_mut(&decl.term);
|
let name = tyenv.intern_mut(&decl.term);
|
||||||
if self.term_map.contains_key(&name) {
|
if let Some(tid) = self.term_map.get(&name) {
|
||||||
tyenv.report_error(
|
tyenv.report_error(
|
||||||
decl.pos,
|
decl.pos,
|
||||||
format!("Duplicate decl for '{}'", decl.term.0),
|
format!("Duplicate decl for '{}'", decl.term.0),
|
||||||
);
|
);
|
||||||
|
tyenv.report_error(
|
||||||
|
self.terms[tid.index()].decl_pos,
|
||||||
|
format!("Duplicate decl for '{}'", decl.term.0),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
self.term_map.insert(name, tid);
|
self.term_map.insert(name, tid);
|
||||||
|
|
||||||
@@ -817,6 +823,7 @@ impl TermEnv {
|
|||||||
|
|
||||||
self.terms.push(Term {
|
self.terms.push(Term {
|
||||||
id: tid,
|
id: tid,
|
||||||
|
decl_pos: decl.pos,
|
||||||
name,
|
name,
|
||||||
arg_tys,
|
arg_tys,
|
||||||
ret_ty,
|
ret_ty,
|
||||||
@@ -855,6 +862,7 @@ impl TermEnv {
|
|||||||
let ret_ty = id;
|
let ret_ty = id;
|
||||||
self.terms.push(Term {
|
self.terms.push(Term {
|
||||||
id: tid,
|
id: tid,
|
||||||
|
decl_pos: pos,
|
||||||
name: variant.fullname,
|
name: variant.fullname,
|
||||||
arg_tys,
|
arg_tys,
|
||||||
ret_ty,
|
ret_ty,
|
||||||
|
|||||||
Reference in New Issue
Block a user