Skip to content

Commit b3999b3

Browse files
committed
Use HIR type table for fresh constructors
1 parent 4927533 commit b3999b3

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

src/ast.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ pub enum FileMode {
99
UsesLocal,
1010
}
1111

12-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13-
pub enum TypeKind {
14-
Class,
15-
Struct,
16-
Resource,
17-
}
18-
1912
#[derive(Debug, Clone)]
2013
pub struct FieldDecl {
2114
pub type_name: String,
@@ -25,7 +18,6 @@ pub struct FieldDecl {
2518
#[derive(Debug, Clone)]
2619
pub struct TypeDecl {
2720
pub name: String,
28-
pub kind: TypeKind,
2921
pub fields: Vec<FieldDecl>,
3022
}
3123

@@ -103,13 +95,6 @@ impl Parser<'_> {
10395
}
10496

10597
fn parse_type_decl(&mut self) {
106-
let kind = if self.at_ident("class") {
107-
TypeKind::Class
108-
} else if self.at_ident("struct") {
109-
TypeKind::Struct
110-
} else {
111-
TypeKind::Resource
112-
};
11398
self.index += 1;
11499
let Some(name) = self.take_ident_name() else {
115100
return;
@@ -154,7 +139,7 @@ impl Parser<'_> {
154139
}
155140
self.program
156141
.types
157-
.insert(name.clone(), TypeDecl { name, kind, fields });
142+
.insert(name.clone(), TypeDecl { name, fields });
158143
self.index = body_end + 1;
159144
}
160145

src/checks/body.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,7 @@ fn check_fresh_return(
682682
}
683683
}
684684
Expr::Ident(name, span)
685-
if !analyzer
686-
.program
687-
.types
688-
.get(name)
689-
.is_some_and(|decl| decl.kind == crate::ast::TypeKind::Struct)
685+
if !is_struct_type(analyzer, name)
690686
&& !analyzer
691687
.hir
692688
.resolve_function(None, name)
@@ -707,11 +703,7 @@ fn check_fresh_return(
707703
}
708704
Expr::Call { callee, span, .. } => {
709705
let constructor_is_struct = match callee {
710-
Callee::Name(name) => analyzer
711-
.program
712-
.types
713-
.get(name)
714-
.is_some_and(|decl| decl.kind == crate::ast::TypeKind::Struct),
706+
Callee::Name(name) => is_struct_type(analyzer, name),
715707
Callee::Qualified { .. } => false,
716708
};
717709
let call_returns_fresh = analyzer
@@ -779,6 +771,10 @@ fn fresh_return_diagnostic(
779771
);
780772
}
781773

774+
fn is_struct_type(analyzer: &Analyzer<'_>, name: &str) -> bool {
775+
analyzer.hir.type_kind(name) == Some(crate::hir::HirTypeKind::Struct)
776+
}
777+
782778
fn infer_expr_type(analyzer: &Analyzer<'_>, expr: &Expr, state: &BodyState) -> Option<String> {
783779
match expr {
784780
Expr::Ident(name, _) => state.value_types.get(name).cloned(),

0 commit comments

Comments
 (0)