Skip to content

Commit

Permalink
Add more implicit conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Mar 4, 2024
1 parent 5827f72 commit bee13d0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ export type State = struct {
// If this is set to true, consteval doesn't perform the walk_top
shallow_walk: bool
current_variable: &scope::Value
// TODO This should be a parameter but its currently too hard to fix
block_implicit_conv: bool
}

def current_value(state: &State) -> &scope::Value {
Expand Down Expand Up @@ -3249,6 +3251,14 @@ def implicit_conversion(node: &parser::Node, tpe: &Type, state: &State) {
node.kind == parser::NodeKind::PTR and
node.value.expr and node.value.expr.kind == parser::NodeKind::IDENTIFIER {
node.tpe = tpe
} else if node.tpe and not equals(node.tpe, tpe) and tpe.length != MAX_UINT64 and not state.block_implicit_conv {
// TODO There are other cases where this is too much work
if convert_type_score(tpe, node.tpe, state.module) >= 0 {
let child = parser::copy_node(node)
@node = [ kind = parser::NodeKind::CAST, loc = node.loc ] !parser::Node
node.value.bin_op = [ left = child ] !parser::NodeBinaryOp
node.tpe = tpe
}
}
}

Expand Down Expand Up @@ -3633,7 +3643,10 @@ def convert_to_call(node: &parser::Node, name: Str, args: &Vector(NamedParameter
let parent = node.parent
@node = @make_function_call(node, ident)
consteval::walk_Call(node, state)
let bic = state.block_implicit_conv
state.block_implicit_conv = true
walk(parent, node, state)
state.block_implicit_conv = bic
}
}

Expand All @@ -3660,7 +3673,10 @@ def convert_to_icall(node: &parser::Node, name: Str, args: &Vector(NamedParamete
vector::push(right, make_function_call(node, ident))
left.push(node.value.bin_op.left)
@node = @assign
let bic = state.block_implicit_conv
state.block_implicit_conv = true
walk(parent, node, state)
state.block_implicit_conv = bic
}
}

Expand Down

0 comments on commit bee13d0

Please sign in to comment.