Skip to content

Commit

Permalink
Move code out of ast::Expression inference
Browse files Browse the repository at this point in the history
  • Loading branch information
emk committed Oct 28, 2023
1 parent 488df6b commit d428ce0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ impl InferTypes for ast::Expression {
ast::Expression::BoolValue(_) => Ok((arg_simple(SimpleType::Bool), scope.clone())),
ast::Expression::Literal(Literal { value, .. }) => value.infer_types(scope),
ast::Expression::Null { .. } => Ok((arg_simple(SimpleType::Null), scope.clone())),
ast::Expression::ColumnName(ident) => {
let ident = ident.to_owned().into();
let ty = scope.get_or_err(&ident)?.try_as_argument_type(&ident)?;
Ok((ty.to_owned(), scope.clone()))
}
ast::Expression::ColumnName(ident) => ident.infer_types(scope),
ast::Expression::TableAndColumnName(name) => name.infer_types(scope),
ast::Expression::Cast(cast) => cast.infer_types(scope),
ast::Expression::FunctionCall(fcall) => fcall.infer_types(scope),
Expand All @@ -412,6 +408,16 @@ impl InferTypes for LiteralValue {
}
}

impl InferTypes for Ident {
type Type = ArgumentType;

fn infer_types(&mut self, scope: &ScopeHandle) -> Result<(Self::Type, ScopeHandle)> {
let ident = self.to_owned().into();
let ty = scope.get_or_err(&ident)?.try_as_argument_type(&ident)?;
Ok((ty.to_owned(), scope.clone()))
}
}

impl InferTypes for ast::TableAndColumnName {
type Type = ArgumentType;

Expand Down

0 comments on commit d428ce0

Please sign in to comment.