All tests passing again.

This commit is contained in:
Jesse Brault 2026-03-21 18:04:13 -05:00
parent 4d6aa3ffd4
commit bb2b539f9b
5 changed files with 20 additions and 68 deletions

View File

@ -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);

View File

@ -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(),
}
}

View File

@ -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);
}
}

View File

@ -12,10 +12,6 @@ pub enum TypeInfo {
String,
Function(Rc<FunctionSymbol>),
Class(Rc<ClassSymbol>),
#[deprecated]
ClassInstance(Rc<ClassSymbol>),
GenericType(Rc<GenericParameterSymbol>),
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!(

View File

@ -209,42 +209,6 @@ mod e2e_tests {
)
}
#[test]
fn two_classes() -> Result<(), Vec<Diagnostic>> {
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<Diagnostic>> {
fn generic_field_and_ctor_param() -> Result<(), Vec<Diagnostic>> {
let context = prepare_context(
"
class Foo<T>