fix: some problems with name resolution

This commit is contained in:
felipegchi 2022-11-16 11:14:29 -03:00
parent 9714dad33c
commit 2f14cc1267
13 changed files with 65 additions and 29 deletions

View File

@ -219,11 +219,15 @@ pub fn run_cli(config: Cli) {
res
});
}
Command::Watch { file: _ } => {
todo!()
},
Command::Repl => {
todo!()
},
Command::ToKDL {
file: _,
namespace: _,
} => todo!(),
Command::Watch { file: _ } => todo!(),
Command::Repl => todo!(),
}
}

View File

@ -1,10 +1,7 @@
type Nat {
succ (pred: Nat)
zero
succ
}
type Vec (t: Type) ~ (n: Nat) {
cons <size: Nat> (x: t) (xs: Vec t size) : Vec t (Nat.succ size)
nil : Vec t Nat.zero
}
Nat.zero : U60
Nat.zero = 2

View File

@ -0,0 +1,3 @@
//! Derives getters and setters for record
//! types.

View File

@ -43,6 +43,8 @@ pub fn to_book(session: &mut Session, path: &PathBuf) -> Option<concrete::Book>
expand::expand_book(&mut concrete_book);
println!("{}", concrete_book);
let failed = resolution::check_unbound_top_level(session, &mut concrete_book);
if failed {

View File

@ -34,7 +34,7 @@ fn accumulate_neighbour_paths(
canon_path.set_extension(EXT);
dir_file_path.push("_");
dir_file_path.set_extension(EXT);
if canon_path.exists() && dir_path.exists() && canon_path.is_file() && dir_path.is_dir() {
Err(DriverError::MultiplePaths(ident.clone(), vec![canon_path, dir_path]).into())
} else if canon_path.is_file() {
@ -249,7 +249,7 @@ pub fn check_unbound_top_level(session: &mut Session, book: &mut Book) -> bool {
unbound::get_book_unbound(session.diagnostic_sender.clone(), book, true);
for (_, unbound) in unbound_tops {
let res: Vec<Ident> = unbound.iter().map(|x| x.to_ident()).collect();
let res: Vec<Ident> = unbound.iter().filter(|x| !x.used_by_sugar).map(|x| x.to_ident()).collect();
if !res.is_empty() {
unbound_variable(session, &book, &res);
failed = true;

View File

@ -492,15 +492,7 @@ impl<'a> Parser<'a> {
range,
});
}
if self.check_and_eat(Token::Colon) {
let expr = self.parse_expr(false)?;
Ok(Box::new(Expr {
range: head.range.mix(expr.range),
data: ExprKind::Ann(head, expr),
}))
} else {
Ok(head)
}
Ok(head)
}
pub fn parse_ask(&mut self) -> Result<Box<Sttm>, SyntaxError> {

View File

@ -18,10 +18,10 @@ fn is_hidden_arg(token: &Token) -> bool {
impl<'a> Parser<'a> {
pub fn is_top_level_entry_continuation(&self) -> bool {
self.peek(1).same_variant(&Token::Colon) // ':'
|| self.peek(1).same_variant(&Token::LPar) // '('
self.peek(1).same_variant(&Token::Colon) // ':'
|| self.peek(1).same_variant(&Token::LPar) // '('
|| self.peek(1).same_variant(&Token::LBrace) // '{'
|| self.peek(1).same_variant(&Token::Less) // '<'
|| self.peek(1).same_variant(&Token::Less) // '<'
|| self.peek(1).same_variant(&Token::Minus) // '-'
|| self.peek(1).same_variant(&Token::Plus) // '+'
}
@ -295,7 +295,9 @@ impl<'a> Parser<'a> {
self.advance();
self.errs.send(err.into()).unwrap();
self.failed = true;
while !self.is_top_level_start() && !self.get().same_variant(&Token::Eof) && !self.is_linebreak() {
while (!self.is_top_level_start() || !self.is_linebreak())
&& !self.get().same_variant(&Token::Eof)
{
self.advance();
}
}

View File

@ -150,10 +150,11 @@ impl<'a> ErasureState<'a> {
visited.insert(hole);
self.unify_loop(range, (left.0, res), right, visited, relevance_unify)
}
(None, Relevance::Irrelevant) => {
self.holes[hole] = Some(t);
true
}
// TODO: It should unify iff we want functions that are considered
// "erased" in the sense that we can just remove them from the runtime and it'll
// be fine.
(None, Relevance::Irrelevant) => false,
(_, _) => true,
},
(Relevance::Relevant, Relevance::Hole(hole)) => match self.holes[hole] {
@ -228,6 +229,15 @@ impl<'a> ErasureState<'a> {
self.ctx.insert(name.to_string(), (name.range, on));
Box::new(pat.clone())
}
Fun(name, spine) | Ctr(name, spine) if on.1 == Relevance::Irrelevant => {
let range = pat.span.to_range().unwrap_or_else(|| name.range.clone());
self.errs
.send(PassError::CannotPatternMatchOnErased(range).into())
.unwrap();
self.failed = true;
self.erase_pat_spine(on, &name, spine);
desugared::Expr::err(range)
}
Fun(name, spine) => {
let spine = self.erase_pat_spine(on, &name, spine);
Box::new(Expr {

View File

@ -31,6 +31,7 @@ pub enum PassError {
ShouldBeAParameter(Span, Range),
NoFieldCoverage(Range, Vec<String>),
DuplicatedConstructor(Range, Range),
CannotPatternMatchOnErased(Range),
}
// TODO: A way to build an error message with methods
@ -89,6 +90,20 @@ impl From<PassError> for DiagnosticFrame {
main: true,
}],
},
PassError::CannotPatternMatchOnErased(place) => DiagnosticFrame {
code: 223,
severity: Severity::Error,
title: "Cannot pattern match on erased arguments.".to_string(),
subtitles: vec![],
hints: vec![],
positions: vec![Marker {
position: place,
color: Color::Fst,
text: "Here!".to_string(),
no_code: false,
main: true,
}],
},
PassError::RulesWithInconsistentArity(arities) => DiagnosticFrame {
code: 201,
severity: Severity::Error,

View File

@ -268,7 +268,7 @@ impl Visitor for UnboundCollector {
fn visit_destruct(&mut self, destruct: &mut Destruct) {
match destruct {
Destruct::Destruct(range, ty, bindings, _) => {
self.visit_qualified_ident(QualifiedIdent::add_segment(ty, "open").to_sugar());
self.visit_qualified_ident(&mut QualifiedIdent::add_segment(ty, "open").to_sugar().to_generated());
self.visit_range(range);
self.visit_qualified_ident(ty);
for bind in bindings {

View File

@ -0,0 +1,8 @@
[package]
name = "kind-query"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

View File

@ -347,7 +347,7 @@ impl Display for Expr {
}
}
Let(name, expr, body) => write!(f, "(let {} = {}; {})", name, expr, body),
Ann(expr, typ) => write!(f, "({} : {})", expr, typ),
Ann(expr, typ) => write!(f, "({} :: {})", expr, typ),
Binary(op, expr, typ) => write!(f, "({} {} {})", op, expr, typ),
Hole(_) => write!(f, "_"),
Hlp(name) => write!(f, "?{}", name),