Add Any type.
This commit is contained in:
parent
ec18b5d5ba
commit
2d601d6115
@ -97,7 +97,11 @@ impl Call {
|
|||||||
for i in 0..parameters.len() {
|
for i in 0..parameters.len() {
|
||||||
let parameter = ¶meters[i];
|
let parameter = ¶meters[i];
|
||||||
let argument = &self.arguments[i];
|
let argument = &self.arguments[i];
|
||||||
if parameter.borrow().type_info() != &argument.type_info() {
|
if !parameter
|
||||||
|
.borrow()
|
||||||
|
.type_info()
|
||||||
|
.is_assignable_from(&argument.type_info())
|
||||||
|
{
|
||||||
diagnostics.push(Diagnostic::new(
|
diagnostics.push(Diagnostic::new(
|
||||||
&format!(
|
&format!(
|
||||||
"Mismatched types; expected {} but found {}",
|
"Mismatched types; expected {} but found {}",
|
||||||
|
|||||||
@ -25,7 +25,7 @@ impl Parameter {
|
|||||||
) -> Result<Rc<RefCell<ParameterSymbol>>, Vec<Diagnostic>> {
|
) -> Result<Rc<RefCell<ParameterSymbol>>, Vec<Diagnostic>> {
|
||||||
let insert_result = symbol_table.insert_parameter_symbol(ParameterSymbol::new(
|
let insert_result = symbol_table.insert_parameter_symbol(ParameterSymbol::new(
|
||||||
&self.declared_name,
|
&self.declared_name,
|
||||||
TypeInfo::String, // todo
|
TypeInfo::Any, // todo
|
||||||
));
|
));
|
||||||
match insert_result {
|
match insert_result {
|
||||||
Ok(parameter_symbol) => Ok(parameter_symbol),
|
Ok(parameter_symbol) => Ok(parameter_symbol),
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum TypeInfo {
|
pub enum TypeInfo {
|
||||||
|
Any,
|
||||||
Integer,
|
Integer,
|
||||||
String,
|
String,
|
||||||
Function(Rc<RefCell<FunctionSymbol>>),
|
Function(Rc<RefCell<FunctionSymbol>>),
|
||||||
@ -12,32 +13,34 @@ pub enum TypeInfo {
|
|||||||
|
|
||||||
impl Display for TypeInfo {
|
impl Display for TypeInfo {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
let s = match self {
|
match self {
|
||||||
TypeInfo::Integer => "Int",
|
TypeInfo::Any => write!(f, "Any"),
|
||||||
TypeInfo::String => "String",
|
TypeInfo::Integer => write!(f, "Int"),
|
||||||
TypeInfo::Function(_) => "fn", // todo
|
TypeInfo::String => write!(f, "String"),
|
||||||
};
|
TypeInfo::Function(function_symbol) => {
|
||||||
write!(f, "{}", s)
|
write!(f, "fn(")?;
|
||||||
|
for parameter in function_symbol.borrow().parameters() {
|
||||||
|
parameter.borrow().type_info().fmt(f)?;
|
||||||
|
}
|
||||||
|
write!(f, ")")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for &TypeInfo {
|
impl TypeInfo {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
pub fn is_assignable_from(&self, other: &TypeInfo) -> bool {
|
||||||
match self {
|
match self {
|
||||||
TypeInfo::Integer => match other {
|
TypeInfo::Any => true,
|
||||||
TypeInfo::Integer => true,
|
TypeInfo::Integer => {
|
||||||
_ => false,
|
matches!(other, TypeInfo::Integer)
|
||||||
},
|
}
|
||||||
TypeInfo::String => match other {
|
TypeInfo::String => {
|
||||||
TypeInfo::String => true,
|
matches!(other, TypeInfo::String)
|
||||||
_ => false,
|
}
|
||||||
},
|
TypeInfo::Function(_) => {
|
||||||
TypeInfo::Function(f0) => match other {
|
unimplemented!("Type matching on Functions not yet supported.")
|
||||||
TypeInfo::Function(f1) => {
|
|
||||||
f0.as_ptr() == f1.as_ptr() // todo
|
|
||||||
}
|
}
|
||||||
_ => false,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user