1
0

Fix type check error

This commit is contained in:
Jeff 2023-12-26 17:52:44 -05:00
parent 2bcb5f59f7
commit a27b33dd36
2 changed files with 22 additions and 10 deletions

View File

@ -10,12 +10,6 @@ is_ready_to_solve = (fn cards <map>) <bool> {
&& ((length cards:weapons) == 1)
}
take_turn = (fn cards <map>, opponent_card <str>, current_room <str>) <map> {
cards = (remove_card cards opponent_card)
cards = (make_guess cards current_room)
cards
}
remove_card = (fn cards <map>, opponent_card <str>) <map> {
cards:rooms -= opponent_card
cards:suspects -= opponent_card
@ -44,6 +38,12 @@ make_guess = (fn cards <map>, current_room <str>) <map> {
cards
}
take_turn = (fn cards <map>, opponent_card <str>, current_room <str>) <map> {
cards = (remove_card cards opponent_card)
cards = (make_guess cards current_room)
cards
}
all_cards
-> (take_turn 'Rope' 'Kitchen')
-> (take_turn 'Library' 'Kitchen')

View File

@ -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),