From a27b33dd36f8c646df6c158bf1c0416a21bb5199 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 26 Dec 2023 17:52:44 -0500 Subject: [PATCH] Fix type check error --- examples/clue_solver.ds | 12 ++++++------ src/abstract_tree/function_call.rs | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/clue_solver.ds b/examples/clue_solver.ds index dce0d5e..2d28e79 100644 --- a/examples/clue_solver.ds +++ b/examples/clue_solver.ds @@ -10,12 +10,6 @@ is_ready_to_solve = (fn cards ) { && ((length cards:weapons) == 1) } -take_turn = (fn cards , opponent_card , current_room ) { - cards = (remove_card cards opponent_card) - cards = (make_guess cards current_room) - cards -} - remove_card = (fn cards , opponent_card ) { cards:rooms -= opponent_card cards:suspects -= opponent_card @@ -44,6 +38,12 @@ make_guess = (fn cards , current_room ) { cards } +take_turn = (fn cards , opponent_card , current_room ) { + cards = (remove_card cards opponent_card) + cards = (make_guess cards current_room) + cards +} + all_cards -> (take_turn 'Rope' 'Kitchen') -> (take_turn 'Library' 'Kitchen') diff --git a/src/abstract_tree/function_call.rs b/src/abstract_tree/function_call.rs index e6c0d8e..a68686a 100644 --- a/src/abstract_tree/function_call.rs +++ b/src/abstract_tree/function_call.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; use tree_sitter::Node; -use crate::{AbstractTree, Error, Map, Result, Type, Value, ValueNode, BUILT_IN_FUNCTIONS}; - -use super::expression::Expression; +use crate::{ + AbstractTree, Error, Expression, Map, Result, Type, Value, ValueNode, BUILT_IN_FUNCTIONS, +}; #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)] pub struct FunctionCall { @@ -144,7 +144,19 @@ impl AbstractTree for FunctionCall { } } - identifier.expected_type(context) + let identifier_type = identifier.expected_type(context)?; + + println!("{identifier_type:?}"); + + if let Type::Function { + parameter_types: _, + return_type, + } = &identifier_type + { + Ok(*return_type.clone()) + } else { + Ok(identifier_type) + } } Expression::Index(index) => index.expected_type(context), Expression::Math(math) => math.expected_type(context),