mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-09-11 08:45:32 +03:00
fix: fixed things in name resolution
This commit is contained in:
parent
bde129fbba
commit
135b1fda86
@ -151,7 +151,7 @@ pub fn derive_match(range: Range, sum: &SumTypeDecl) -> concrete::Entry {
|
||||
types.push(Argument {
|
||||
hidden: false,
|
||||
erased: false,
|
||||
name: Ident::new_static("_", range),
|
||||
name: Ident::new_static(&format!("_{}", cons.name.to_string()), range),
|
||||
typ: Some(cons_type),
|
||||
range,
|
||||
});
|
||||
|
@ -61,7 +61,7 @@ impl From<DriverError> for DiagnosticFrame {
|
||||
DriverError::DefinedMultipleTimes(fst, snd) => DiagnosticFrame {
|
||||
code: 102,
|
||||
severity: Severity::Error,
|
||||
title: "Multiple paths for the same name".to_string(),
|
||||
title: "Defined multiple times for the same name".to_string(),
|
||||
subtitles: vec![],
|
||||
hints: vec![
|
||||
"Rename one of the definitions or remove and look at how names work in Kind at https://kind.kindelia.org/hints/names".to_string()
|
||||
|
@ -72,18 +72,22 @@ fn ident_to_path(
|
||||
}
|
||||
}
|
||||
|
||||
fn try_to_insert_new_name<'a>(session: &'a Session, ident: QualifiedIdent, book: &'a mut Book) {
|
||||
fn try_to_insert_new_name<'a>(failed: &mut bool, session: &'a Session, ident: QualifiedIdent, book: &'a mut Book) -> bool {
|
||||
if let Some(first_occorence) = book.names.get(ident.to_string().as_str()) {
|
||||
session
|
||||
.diagnostic_sender
|
||||
.send(DriverError::DefinedMultipleTimes(first_occorence.clone(), ident).into())
|
||||
.unwrap();
|
||||
*failed = true;
|
||||
false
|
||||
} else {
|
||||
book.names.insert(ident.to_string(), ident);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn module_to_book<'a>(
|
||||
failed: &mut bool,
|
||||
session: &'a Session,
|
||||
module: &Module,
|
||||
book: &'a mut Book,
|
||||
@ -94,25 +98,25 @@ fn module_to_book<'a>(
|
||||
match &entry {
|
||||
TopLevel::SumType(sum) => {
|
||||
public_names.insert(sum.name.to_string());
|
||||
try_to_insert_new_name(session, sum.name.clone(), book);
|
||||
book.count
|
||||
.insert(sum.name.to_string(), sum.extract_book_info());
|
||||
|
||||
book.entries.insert(sum.name.to_string(), entry.clone());
|
||||
if try_to_insert_new_name(failed, session, sum.name.clone(), book) {
|
||||
book.count.insert(sum.name.to_string(), sum.extract_book_info());
|
||||
book.entries.insert(sum.name.to_string(), entry.clone());
|
||||
}
|
||||
|
||||
for cons in &sum.constructors {
|
||||
let cons_ident = sum.name.add_segment(cons.name.to_str());
|
||||
public_names.insert(cons_ident.to_string());
|
||||
book.count
|
||||
.insert(cons_ident.to_string(), cons.extract_book_info(sum));
|
||||
try_to_insert_new_name(session, cons_ident, book);
|
||||
let mut cons_ident = sum.name.add_segment(cons.name.to_str());
|
||||
cons_ident.range = cons.name.range.clone();
|
||||
if try_to_insert_new_name(failed, session, cons_ident.clone(), book) {
|
||||
public_names.insert(cons_ident.to_string());
|
||||
book.count.insert(cons_ident.to_string(), cons.extract_book_info(sum));
|
||||
}
|
||||
}
|
||||
}
|
||||
TopLevel::RecordType(rec) => {
|
||||
public_names.insert(rec.name.to_string());
|
||||
book.count
|
||||
.insert(rec.name.to_string(), rec.extract_book_info());
|
||||
try_to_insert_new_name(session, rec.name.clone(), book);
|
||||
try_to_insert_new_name(failed, session, rec.name.clone(), book);
|
||||
|
||||
book.entries.insert(rec.name.to_string(), entry.clone());
|
||||
|
||||
@ -122,10 +126,10 @@ fn module_to_book<'a>(
|
||||
cons_ident.to_string(),
|
||||
rec.extract_book_info_of_constructor(),
|
||||
);
|
||||
try_to_insert_new_name(session, cons_ident, book);
|
||||
try_to_insert_new_name(failed, session, cons_ident, book);
|
||||
}
|
||||
TopLevel::Entry(entr) => {
|
||||
try_to_insert_new_name(session, entr.name.clone(), book);
|
||||
try_to_insert_new_name(failed, session, entr.name.clone(), book);
|
||||
public_names.insert(entr.name.to_string());
|
||||
book.count
|
||||
.insert(entr.name.to_string(), entr.extract_book_info());
|
||||
@ -198,7 +202,7 @@ fn parse_and_store_book_by_path<'a>(
|
||||
|
||||
failed |= expand_uses(&mut module, session.diagnostic_sender.clone());
|
||||
|
||||
module_to_book(session, &module, book);
|
||||
module_to_book(&mut failed, session, &module, book);
|
||||
|
||||
failed
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ impl<'a> DesugarState<'a> {
|
||||
|
||||
let name = match name {
|
||||
Some(ident) => ident.clone(),
|
||||
None => Ident::generate("_"),
|
||||
None => Ident::generate("_var"),
|
||||
};
|
||||
|
||||
let spine = vec![
|
||||
|
@ -29,7 +29,8 @@ pub enum PassError {
|
||||
CannotFindAlias(String, Range),
|
||||
NotATypeConstructor(Range, Range),
|
||||
ShouldBeAParameter(Span, Range),
|
||||
NoFieldCoverage(Range, Vec<String>)
|
||||
NoFieldCoverage(Range, Vec<String>),
|
||||
DuplicatedConstructor(Range, Range),
|
||||
}
|
||||
|
||||
// TODO: A way to build an error message with methods
|
||||
@ -428,6 +429,27 @@ impl From<PassError> for DiagnosticFrame {
|
||||
main: true,
|
||||
}],
|
||||
},
|
||||
PassError::DuplicatedConstructor(place, other) => DiagnosticFrame {
|
||||
code: 209,
|
||||
severity: Severity::Error,
|
||||
title: "Duplicated constructor name".to_string(),
|
||||
subtitles: vec![],
|
||||
hints: vec![],
|
||||
positions: vec![Marker {
|
||||
position: place,
|
||||
color: Color::Fst,
|
||||
text: "Here".to_string(),
|
||||
no_code: false,
|
||||
main: true,
|
||||
},
|
||||
Marker {
|
||||
position: other,
|
||||
color: Color::Fst,
|
||||
text: "Here".to_string(),
|
||||
no_code: false,
|
||||
main: false,
|
||||
}],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,10 +165,27 @@ impl Visitor for UnboundCollector {
|
||||
TopLevel::SumType(entr) => {
|
||||
self.context_vars
|
||||
.push((entr.name.range, entr.name.to_string()));
|
||||
|
||||
let mut repeated_names = FxHashMap::<String, Range>::default();
|
||||
let mut failed = false;
|
||||
|
||||
for cons in &entr.constructors {
|
||||
|
||||
match repeated_names.get(&cons.name.to_string()) {
|
||||
Some(_) => {
|
||||
failed = true;
|
||||
},
|
||||
None => {
|
||||
repeated_names.insert(cons.name.to_string(), cons.name.range);
|
||||
},
|
||||
}
|
||||
|
||||
let name_cons = entr.name.add_segment(cons.name.to_str());
|
||||
self.context_vars
|
||||
.push((name_cons.range, name_cons.to_string()));
|
||||
self.context_vars.push((name_cons.range, name_cons.to_string()));
|
||||
}
|
||||
|
||||
if failed {
|
||||
return;
|
||||
}
|
||||
|
||||
let vars = self.context_vars.clone();
|
||||
|
Loading…
Reference in New Issue
Block a user