From e079bbd31225f512a3954375a5346493111bb0fc Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 17 Nov 2024 16:30:59 +0100 Subject: [PATCH] forgot to support explicit enum type --- lang/src/son.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lang/src/son.rs b/lang/src/son.rs index 7b43812..926e591 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -2877,6 +2877,32 @@ impl<'a> Codegen<'a> { }; } + if let ty::Kind::Enum(e) = tty.expand() { + let intrnd = self.tys.names.project(name); + let Some(index) = + self.tys.enum_fields(e).iter().position(|f| Some(f.name) == intrnd) + else { + let field_list = self + .tys + .enum_fields(e) + .iter() + .map(|f| self.tys.names.ident_str(f.name)) + .intersperse("', '") + .collect::(); + self.report( + pos, + fa!( + "the '{}' does not have this variant, \ + but it does have '{field_list}'", + self.ty_display(tty) + ), + ); + return Value::NEVER; + }; + + return Some(self.ci.nodes.new_const_lit(tty, index as i64)); + } + let ty::Kind::Struct(s) = self.tys.base_of(tty).unwrap_or(tty).expand() else { self.report( pos,