diff --git a/compiler/ast/src/functions/input/function_input.rs b/compiler/ast/src/functions/input/function_input.rs index 4aa10eec78..be5afef527 100644 --- a/compiler/ast/src/functions/input/function_input.rs +++ b/compiler/ast/src/functions/input/function_input.rs @@ -44,14 +44,33 @@ impl fmt::Display for ParamMode { pub struct FunctionInputVariable { /// The name the parameter is accessible as in the function's body. pub identifier: Identifier, - /// Is it a const parameter? - pub mode: ParamMode, + /// The mode of the function parameter. + mode: ParamMode, /// What's the parameter's type? - pub type_: Type, + type_: Type, /// The parameters span from any annotations to its type. pub span: Span, } +impl FunctionInputVariable { + pub fn new(identifier: Identifier, mode: ParamMode, type_: Type, span: Span) -> Self { + Self { + identifier, + mode, + type_, + span, + } + } + + pub fn mode(&self) -> ParamMode { + self.mode + } + + pub fn type_(&self) -> Type { + self.type_.clone() + } +} + impl FunctionInputVariable { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{} ", self.mode)?; diff --git a/compiler/ast/src/reducer/reconstructing_director.rs b/compiler/ast/src/reducer/reconstructing_director.rs index 06161ac65c..ad2da4acc1 100644 --- a/compiler/ast/src/reducer/reconstructing_director.rs +++ b/compiler/ast/src/reducer/reconstructing_director.rs @@ -282,7 +282,7 @@ impl ReconstructingDirector { variable: &FunctionInputVariable, ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; - let type_ = self.reduce_type(&variable.type_, &variable.span)?; + let type_ = self.reduce_type(&variable.type_(), &variable.span)?; self.reducer.reduce_function_input_variable(variable, identifier, type_) } diff --git a/compiler/ast/src/reducer/reconstructing_reducer.rs b/compiler/ast/src/reducer/reconstructing_reducer.rs index d47053ad4e..9d0bc2e46d 100644 --- a/compiler/ast/src/reducer/reconstructing_reducer.rs +++ b/compiler/ast/src/reducer/reconstructing_reducer.rs @@ -272,12 +272,12 @@ pub trait ReconstructingReducer { identifier: Identifier, type_: Type, ) -> Result { - Ok(FunctionInputVariable { + Ok(FunctionInputVariable::new( identifier, - mode: variable.mode, + variable.mode(), type_, - span: variable.span.clone(), - }) + variable.span.clone(), + )) } fn reduce_function_input(&mut self, _input: &FunctionInput, new: FunctionInput) -> Result { diff --git a/compiler/parser/src/parser/file.rs b/compiler/parser/src/parser/file.rs index c1211d93ba..a90b35165f 100644 --- a/compiler/parser/src/parser/file.rs +++ b/compiler/parser/src/parser/file.rs @@ -91,12 +91,12 @@ impl ParserContext<'_> { self.expect(Token::Colon)?; let type_ = self.parse_type()?.0; - Ok(FunctionInput::Variable(FunctionInputVariable { + Ok(FunctionInput::Variable(FunctionInputVariable::new( + name.clone(), mode, type_, - span: name.span.clone(), - identifier: name, - })) + name.span, + ))) } /// Returns an [`(Identifier, Function)`] AST node if the next tokens represent a function name