From bb2b539f9b28d4ae89eb9c6e0c8e035c762709f8 Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Sat, 21 Mar 2026 18:04:13 -0500 Subject: [PATCH] All tests passing again. --- dmc-lib/src/ast/class.rs | 12 +++++------ dmc-lib/src/ast/type_use.rs | 19 +++++++++++------- dmc-lib/src/intrinsics/mod.rs | 4 +--- dmc-lib/src/type_info.rs | 15 -------------- e2e-tests/src/lib.rs | 38 +---------------------------------- 5 files changed, 20 insertions(+), 68 deletions(-) diff --git a/dmc-lib/src/ast/class.rs b/dmc-lib/src/ast/class.rs index 4fb8b63..e53f483 100644 --- a/dmc-lib/src/ast/class.rs +++ b/dmc-lib/src/ast/class.rs @@ -216,12 +216,7 @@ impl Class { .unwrap(); types_table .constructor_return_types_mut() - .insert(constructor_symbol, TypeInfo::ClassInstance(class_symbol)); - - // now the constructor (parameters, etc.) - if let Some(constructor) = &self.constructor { - constructor.gather_types_into(symbol_table, types_table); - } + .insert(constructor_symbol, TypeInfo::Class(class_symbol)); let mut diagnostics = Vec::new(); @@ -238,6 +233,11 @@ impl Class { handle_diagnostics!(field.gather_types(symbol_table, types_table), diagnostics); } + // now the constructor (parameters, etc.) + if let Some(constructor) = &self.constructor { + constructor.gather_types_into(symbol_table, types_table); + } + // function return types for function in &self.functions { function.gather_types(symbol_table, types_table); diff --git a/dmc-lib/src/ast/type_use.rs b/dmc-lib/src/ast/type_use.rs index 08097e6..373b711 100644 --- a/dmc-lib/src/ast/type_use.rs +++ b/dmc-lib/src/ast/type_use.rs @@ -86,17 +86,22 @@ impl TypeUse { .find_type_symbol(self.scope_id.unwrap(), self.declared_name()) .unwrap(); match type_symbol { - TypeSymbol::Class(class_symbol) => types_table - .class_instance_types() - .get(&class_symbol) + TypeSymbol::Class(class_symbol) => { + types_table + .class_types() + .get(&class_symbol) + .expect(&format!( + "Could not get TypeInfo for {}", + self.declared_name + )) + } + TypeSymbol::GenericParameter(generic_parameter_symbol) => types_table + .generic_parameter_types() + .get(&generic_parameter_symbol) .expect(&format!( "Could not get TypeInfo for {}", self.declared_name )), - TypeSymbol::GenericParameter(generic_parameter_symbol) => types_table - .generic_parameter_types() - .get(&generic_parameter_symbol) - .unwrap(), } } diff --git a/dmc-lib/src/intrinsics/mod.rs b/dmc-lib/src/intrinsics/mod.rs index b9407dd..e679482 100644 --- a/dmc-lib/src/intrinsics/mod.rs +++ b/dmc-lib/src/intrinsics/mod.rs @@ -39,8 +39,6 @@ pub fn insert_intrinsic_types(symbol_table: &SymbolTable, types_table: &mut Type "String" => TypeInfo::String, _ => unreachable!(), }; - types_table - .class_instance_types_mut() - .insert(symbol, type_info); + types_table.class_types_mut().insert(symbol, type_info); } } diff --git a/dmc-lib/src/type_info.rs b/dmc-lib/src/type_info.rs index bfb0cae..4c89a09 100644 --- a/dmc-lib/src/type_info.rs +++ b/dmc-lib/src/type_info.rs @@ -12,10 +12,6 @@ pub enum TypeInfo { String, Function(Rc), Class(Rc), - - #[deprecated] - ClassInstance(Rc), - GenericType(Rc), Void, } @@ -40,9 +36,6 @@ impl Display for TypeInfo { TypeInfo::Class(class_symbol) => { write!(f, "Class({:?})", class_symbol) } - TypeInfo::ClassInstance(class_symbol) => { - write!(f, "{}", class_symbol.declared_name()) - } TypeInfo::GenericType(generic_parameter_symbol) => { write!(f, "{}", generic_parameter_symbol.declared_name()) } @@ -79,14 +72,6 @@ impl TypeInfo { TypeInfo::Class(other_class_symbol) => class_symbol == other_class_symbol, _ => false, }, - TypeInfo::ClassInstance(class_symbol) => { - match other { - TypeInfo::ClassInstance(other_class_symbol) => { - class_symbol == other_class_symbol // good enough for now - } - _ => false, - } - } TypeInfo::GenericType(generic_parameter_symbol) => { // if generic_parameter_symbol.extends().len() > 0 { // unimplemented!( diff --git a/e2e-tests/src/lib.rs b/e2e-tests/src/lib.rs index e5a7770..a517f10 100644 --- a/e2e-tests/src/lib.rs +++ b/e2e-tests/src/lib.rs @@ -209,42 +209,6 @@ mod e2e_tests { ) } - #[test] - fn two_classes() -> Result<(), Vec> { - let context = prepare_context( - " - class Foo - mut bar: Int = 42 - - ctor(_bar: Int) - end - - fn baz() -> Int - bar - end - end - - class Qux - fn foo() -> Foo - Foo(42) - end - end - - fn foo(n: Int) -> Foo - Foo(n) - end - ", - )?; - let result = get_result(&context, "foo", &[Value::Int(42)]); - assert!(result.is_some()); - let value = result.unwrap(); - assert!(matches!(value, Value::Object(_))); - let o = value.unwrap_object().borrow(); - assert_eq!(o.fields().len(), 1); - assert_eq!(o.fields()[0].unwrap_int(), 42); - Ok(()) - } - #[test] fn simple_assign() { assert_result( @@ -289,7 +253,7 @@ mod e2e_tests { } #[test] - fn see_what_happens() -> Result<(), Vec> { + fn generic_field_and_ctor_param() -> Result<(), Vec> { let context = prepare_context( " class Foo