From d31b6437ac51706221fab1081810ccbdf5fe4d88 Mon Sep 17 00:00:00 2001 From: Rigidity Date: Tue, 16 Apr 2024 16:48:42 -0400 Subject: [PATCH] Warn for redundant optionals --- crates/rue-compiler/src/error.rs | 3 +++ crates/rue-compiler/src/lowerer.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/crates/rue-compiler/src/error.rs b/crates/rue-compiler/src/error.rs index 9e40d20..f68f81b 100644 --- a/crates/rue-compiler/src/error.rs +++ b/crates/rue-compiler/src/error.rs @@ -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. diff --git a/crates/rue-compiler/src/lowerer.rs b/crates/rue-compiler/src/lowerer.rs index 6747b8c..23c382b 100644 --- a/crates/rue-compiler/src/lowerer.rs +++ b/crates/rue-compiler/src/lowerer.rs @@ -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)) }