diff --git a/lang/src/son.rs b/lang/src/son.rs index 7b43812f..926e5916 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,