Skip to content

Commit

Permalink
Warn for redundant optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Apr 16, 2024
1 parent 6804337 commit d31b643
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/rue-compiler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ pub enum DiagnosticInfo {

#[error("cannot check equality on non-atom type `{0}`")]
NonAtomEquality(String),

#[error("redundant optional type")]
RedundantOptional,
}

/// Join a list of names into a string, wrapped in backticks.
Expand Down
8 changes: 8 additions & 0 deletions crates/rue-compiler/src/lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,14 @@ impl<'a> Lowerer<'a> {
.map(|ty| self.compile_type(ty))
.unwrap_or(self.unknown_type);

if let Type::Optional(inner) = self.db.ty_raw(ty).clone() {
self.warning(
DiagnosticInfo::RedundantOptional,
optional.syntax().text_range(),
);
return inner;
}

self.db.alloc_type(Type::Optional(ty))
}

Expand Down

0 comments on commit d31b643

Please sign in to comment.