Skip to content

Commit

Permalink
Merge pull request #9 from Rigidity/cleanup
Browse files Browse the repository at this point in the history
Initial cleanup effort
  • Loading branch information
Rigidity authored Jun 24, 2024
2 parents ab0a920 + 0ab216a commit f8630e3
Show file tree
Hide file tree
Showing 30 changed files with 910 additions and 567 deletions.
30 changes: 17 additions & 13 deletions crates/rue-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
hir::Hir,
scope::Scope,
ty::{FunctionType, PairType, Rest, Type, Value},
Comparison, ErrorKind,
ErrorKind,
};

mod block;
Expand Down Expand Up @@ -139,13 +139,6 @@ impl<'a> Compiler<'a> {
}
}

fn try_unwrap_optional(&mut self, ty: TypeId) -> TypeId {
match self.db.ty(ty) {
Type::Optional(inner) => self.try_unwrap_optional(*inner),
_ => ty,
}
}

fn detect_cycle(&mut self, type_id: TypeId, text_range: TextRange) -> bool {
if self.db.is_cyclic(type_id) {
self.db.error(ErrorKind::RecursiveTypeAlias, text_range);
Expand Down Expand Up @@ -213,7 +206,18 @@ impl<'a> Compiler<'a> {
format!(
"{}::{} {{ {} }}",
enum_name,
enum_variant.name,
match self.db.ty(enum_variant.enum_type) {
Type::Enum(enum_type) => {
enum_type
.variants
.iter()
.find(|item| *item.1 == ty)
.expect("enum type is missing variant")
.0
.clone()
}
_ => unreachable!(),
},
fields.join(", ")
)
}
Expand Down Expand Up @@ -245,10 +249,10 @@ impl<'a> Compiler<'a> {
self.db
.compare_type_with_generics(from, to, &mut self.generic_type_stack)
} else {
self.db.compare_type_raw(from, to)
self.db.compare_type(from, to)
};

if comparison > Comparison::Assignable {
if !comparison.is_assignable() {
self.db.error(
ErrorKind::TypeMismatch {
expected: self.type_name(to),
Expand All @@ -264,10 +268,10 @@ impl<'a> Compiler<'a> {
self.db
.compare_type_with_generics(from, to, &mut self.generic_type_stack)
} else {
self.db.compare_type_raw(from, to)
self.db.compare_type(from, to)
};

if comparison > Comparison::Castable {
if !comparison.is_castable() {
self.db.error(
ErrorKind::CastMismatch {
expected: self.type_name(to),
Expand Down
2 changes: 1 addition & 1 deletion crates/rue-compiler/src/compiler/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Compiler<'_> {
Expr::PrefixExpr(prefix) => self.compile_prefix_expr(prefix),
Expr::BinaryExpr(binary) => self.compile_binary_expr(binary),
Expr::GroupExpr(expr) => self.compile_group_expr(expr, expected_type),
Expr::CastExpr(cast) => self.compile_cast_expr(cast, expected_type),
Expr::CastExpr(cast) => self.compile_cast_expr(cast),
Expr::GuardExpr(guard) => self.compile_guard_expr(guard, expected_type),
Expr::IfExpr(if_expr) => self.compile_if_expr(if_expr, expected_type),
Expr::FunctionCallExpr(call) => self.compile_function_call_expr(call),
Expand Down
Loading

0 comments on commit f8630e3

Please sign in to comment.