forgot to support explicit enum type

This commit is contained in:
Jakub Doka 2024-11-17 16:30:59 +01:00
parent 12b9d43754
commit e079bbd312
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143

View file

@ -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::<String>();
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 { let ty::Kind::Struct(s) = self.tys.base_of(tty).unwrap_or(tty).expand() else {
self.report( self.report(
pos, pos,