Skip to content

Commit

Permalink
Fix ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Apr 16, 2024
1 parent 84b4aa7 commit 6804337
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 8 additions & 10 deletions crates/rue-compiler/src/lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,8 @@ impl<'a> Lowerer<'a> {
DiagnosticInfo::NonAtomEquality(self.type_name(lhs.ty())),
text_range,
);
} else {
self.type_check(rhs.ty(), lhs.ty(), text_range);
}

if self.is_assignable_to(lhs.ty(), self.nil_type, false, &mut HashSet::new()) {
} else if self.is_assignable_to(lhs.ty(), self.nil_type, false, &mut HashSet::new())
{
if let Hir::Reference(symbol_id) = self.db.hir(rhs.hir()) {
guards.insert(
*symbol_id,
Expand All @@ -1040,6 +1037,8 @@ impl<'a> Lowerer<'a> {
Guard::new(self.nil_type, self.try_unwrap_optional(lhs.ty())),
);
}
} else {
self.type_check(rhs.ty(), lhs.ty(), text_range);
}

(BinOp::Equals, self.bool_type)
Expand All @@ -1052,11 +1051,8 @@ impl<'a> Lowerer<'a> {
DiagnosticInfo::NonAtomEquality(self.type_name(lhs.ty())),
text_range,
);
} else {
self.type_check(rhs.ty(), lhs.ty(), text_range);
}

if self.is_assignable_to(lhs.ty(), self.nil_type, false, &mut HashSet::new()) {
} else if self.is_assignable_to(lhs.ty(), self.nil_type, false, &mut HashSet::new())
{
if let Hir::Reference(symbol_id) = self.db.hir(rhs.hir()) {
guards.insert(
*symbol_id,
Expand All @@ -1071,6 +1067,8 @@ impl<'a> Lowerer<'a> {
Guard::new(self.try_unwrap_optional(lhs.ty()), self.nil_type),
);
}
} else {
self.type_check(rhs.ty(), lhs.ty(), text_range);
}

(BinOp::NotEquals, self.bool_type)
Expand Down
12 changes: 6 additions & 6 deletions crates/rue-parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn let_stmt(p: &mut Parser) {
fn if_stmt_maybe_else(p: &mut Parser, expr_only: bool) -> bool {
let cp = p.checkpoint();
p.expect(SyntaxKind::If);
expr(p);
expr_binding_power(p, 0, false);
block(p);
let mut has_else = false;
if expr_only || p.at(SyntaxKind::Else) {
Expand Down Expand Up @@ -241,14 +241,14 @@ fn binding_power(op: BinaryOp) -> (u8, u8) {
const EXPR_RECOVERY_SET: &[SyntaxKind] = &[SyntaxKind::OpenBrace, SyntaxKind::CloseBrace];

fn expr(p: &mut Parser) {
expr_binding_power(p, 0);
expr_binding_power(p, 0, true);
}

fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) {
fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8, allow_initializer: bool) {
if p.at(SyntaxKind::Not) {
p.start(SyntaxKind::PrefixExpr);
p.bump();
expr_binding_power(p, 255);
expr_binding_power(p, 255, allow_initializer);
p.finish();
return;
}
Expand All @@ -267,7 +267,7 @@ fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) {
} else if p.at(SyntaxKind::Ident) {
path(p);

if p.at(SyntaxKind::OpenBrace) {
if p.at(SyntaxKind::OpenBrace) && allow_initializer {
p.start_at(checkpoint, SyntaxKind::InitializerExpr);
p.bump();
while !p.at(SyntaxKind::CloseBrace) {
Expand Down Expand Up @@ -381,7 +381,7 @@ fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) {
p.bump();

p.start_at(checkpoint, SyntaxKind::BinaryExpr);
expr_binding_power(p, right_binding_power);
expr_binding_power(p, right_binding_power, allow_initializer);
p.finish();
}
}
Expand Down

0 comments on commit 6804337

Please sign in to comment.