Resolver - Support and detection of the initializer scope type

This commit is contained in:
Emmanuel BENOîT 2023-01-11 15:19:21 +01:00
parent 0a581f042d
commit aa48973e23

View file

@ -44,8 +44,13 @@ enum SymKind {
/// The type of a scope /// The type of a scope
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum ScopeType { enum ScopeType {
/// The scope is contained by the top-level scope.
TopLevel, TopLevel,
/// The scope is contained by a function.
Function, Function,
/// The scope is contained by an instance initializer.
Initializer,
/// The scope is contained by a method.
Method, Method,
} }
@ -269,7 +274,11 @@ where
methods.iter().try_for_each(|method| { methods.iter().try_for_each(|method| {
rs.with_scope( rs.with_scope(
|rs| resolve_function(rs, &method.params, &method.body), |rs| resolve_function(rs, &method.params, &method.body),
ScopeType::Method, if method.name.lexeme == "init" {
ScopeType::Initializer
} else {
ScopeType::Method
},
) )
}) })
} }