Skip to content

Commit

Permalink
Hack your way to success
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jan 31, 2025
1 parent 4688ccf commit 8d07deb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
6 changes: 1 addition & 5 deletions compiler/noirc_frontend/src/elaborator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ impl Elaborator<'_> {
self_type: &Type,
) {
let name = &variant.name;
let name_string = name.to_string();
let location = Location::new(variant.name.span(), self.file);

let global_id = self.interner.push_empty_global(
Expand All @@ -79,16 +78,13 @@ impl Elaborator<'_> {
false,
);

let kind = DefinitionKind::Global(global_id);
let definition_id =
self.interner.push_definition(name_string, false, false, kind, location);

let mut typ = self_type.clone();
if !datatype.borrow().generics.is_empty() {
let typevars = vecmap(&datatype.borrow().generics, |generic| generic.type_var.clone());
typ = Type::Forall(typevars, Box::new(typ));
}

let definition_id = self.interner.get_global(global_id).definition_id;
self.interner.push_definition_type(definition_id, typ.clone());

let no_parameters = Parameters(Vec::new());
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
id: ExprId,
) -> IResult<Value> {
let fields = try_vecmap(constructor.arguments, |arg| self.evaluate(arg))?;
let typ = self.elaborator.interner.id_type(id).follow_bindings();
let typ = self.elaborator.interner.id_type(id).unwrap_forall().1.follow_bindings();
Ok(Value::Enum(constructor.variant_index, fields, typ))
}

Expand Down
1 change: 0 additions & 1 deletion test_programs/compile_success_empty/enums/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ fn main() {
let _b: Foo<u16> = Foo::B(3);
let _c = Foo::C(4);

// (#7172): Single variant enums must be called as functions currently
let _d: fn() -> Foo<(i32, i32)> = Foo::D;
let _d: Foo<(i32, i32)> = Foo::D();
let _e: Foo<u16> = Foo::E;
Expand Down

0 comments on commit 8d07deb

Please sign in to comment.