fixed bug with function args and custom types

This commit is contained in:
mark 2023-05-12 15:03:20 +02:00
parent f76ff55401
commit c501a6e558
3 changed files with 14 additions and 12 deletions

View File

@ -553,7 +553,7 @@ impl BuiltinFunction {
for (i, o) in io { for (i, o) in io {
if i.iter() if i.iter()
.zip(input.iter().skip(1)) .zip(input.iter().skip(1))
.all(|(i, input)| input.contains(i)) .all(|(i, input)| input.contains(i, info))
{ {
out = out | o; out = out | o;
} }
@ -694,8 +694,8 @@ impl BuiltinFunction {
let mut might_be_string = false; let mut might_be_string = false;
if let Self::Add = self { if let Self::Add = self {
match ( match (
input[0].contains(&VSingleType::String), input[0].contains(&VSingleType::String, info),
input[1].contains(&VSingleType::String), input[1].contains(&VSingleType::String, info),
) { ) {
(true, true) => might_be_string = true, (true, true) => might_be_string = true,
(true, false) | (false, true) => unreachable!(), (true, false) | (false, true) => unreachable!(),
@ -704,12 +704,12 @@ impl BuiltinFunction {
} }
let o = match ( let o = match (
( (
input[0].contains(&VSingleType::Int), input[0].contains(&VSingleType::Int, info),
input[0].contains(&VSingleType::Float), input[0].contains(&VSingleType::Float, info),
), ),
( (
input[1].contains(&VSingleType::Int), input[1].contains(&VSingleType::Int, info),
input[1].contains(&VSingleType::Float), input[1].contains(&VSingleType::Float, info),
), ),
) { ) {
((true, false), (true, false)) => VSingleType::Int.to(), ((true, false), (true, false)) => VSingleType::Int.to(),

View File

@ -58,13 +58,13 @@ impl RFunction {
}) })
.expect("invalid args for function! possible issue with type-checker if this can be reached! feel free to report a bug.") .expect("invalid args for function! possible issue with type-checker if this can be reached! feel free to report a bug.")
} }
pub fn out_vt(&self, input_types: &Vec<VType>) -> VType { pub fn out_vt(&self, input_types: &Vec<VType>, info: &GlobalScriptInfo) -> VType {
let mut out = VType { types: vec![] }; let mut out = VType { types: vec![] };
for (itype, otype) in self.input_output_map.iter() { for (itype, otype) in self.input_output_map.iter() {
if itype if itype
.iter() .iter()
.zip(input_types.iter()) .zip(input_types.iter())
.all(|(expected, got)| got.contains(expected)) .all(|(expected, got)| got.contains(expected, info))
{ {
out = out | otype; out = out | otype;
} }
@ -305,7 +305,9 @@ impl RStatementEnum {
t.clone() t.clone()
} }
} }
Self::FunctionCall(f, args) => f.out_vt(&args.iter().map(|v| v.out(info)).collect()), Self::FunctionCall(f, args) => {
f.out_vt(&args.iter().map(|v| v.out(info)).collect(), info)
}
Self::LibFunction(.., out) => out.clone(), Self::LibFunction(.., out) => out.clone(),
Self::Block(b) => b.out(info), Self::Block(b) => b.out(info),
Self::If(_, a, b) => { Self::If(_, a, b) => {

View File

@ -176,8 +176,8 @@ impl VType {
t.enum_variants(enum_variants); t.enum_variants(enum_variants);
} }
} }
pub fn contains(&self, t: &VSingleType) -> bool { pub fn contains(&self, t: &VSingleType, info: &GlobalScriptInfo) -> bool {
self.types.contains(t) self.types.iter().any(|s| t.fits_in(s, info))
} }
pub fn noenum(self) -> Self { pub fn noenum(self) -> Self {
let mut o = Self { types: vec![] }; let mut o = Self { types: vec![] };