Skip to content

Commit

Permalink
Merge branch 'weak_ref'
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed May 5, 2024
2 parents 628d77c + 7a1922f commit 8cabfa9
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/typechecking.pr
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,12 @@ def lookup_field_type(node: &parser::Node, state: &State, current_type: &Type, c
node.kind == parser::NodeKind::WEAK_REF_T or
node.kind == parser::NodeKind::FUNCTION_T or
node.kind == parser::NodeKind::CLOSURE_T {

let prev_node = node
if node.kind == parser::NodeKind::WEAK_REF_T {
// Unwrap weak ref
node = node.value.t_parr.tpe
}

if node.kind == parser::NodeKind::FUNCTION_T {
let box = box(type_lookup(node, state, current_type, false, cache))
Expand Down Expand Up @@ -2564,18 +2570,24 @@ def lookup_field_type(node: &parser::Node, state: &State, current_type: &Type, c
}
}

if node.kind == parser::NodeKind::PTR_T {
if prev_node.kind == parser::NodeKind::PTR_T {
stub = pointer(stub, node.value.t_parr.kw)
} else if node.kind == parser::NodeKind::REF_T {
} else if prev_node.kind == parser::NodeKind::REF_T {
stub = reference(stub, node.value.t_parr.kw)
} else if node.kind == parser::NodeKind::ARRAY_T {
} else if prev_node.kind == parser::NodeKind::ARRAY_T {
stub = array(stub, node.value.t_parr.kw)
} else if node.kind == parser::NodeKind::WEAK_REF_T {
}

if prev_node.kind == parser::NodeKind::WEAK_REF_T {
stub = weak_reference(stub, node.value.t_parr.kw)
stub.module = state.module
stub.node = node
prev_node.tpe = stub
} else {
stub.module = state.module
stub.node = node
node.tpe = stub
}
stub.module = state.module
stub.node = node
node.tpe = stub

return stub
} else {
Expand Down Expand Up @@ -5622,12 +5634,16 @@ export def lookup_struct_member(member: StructMember, resolved: &SSet = null) {

if (tpe.kind == TypeKind::POINTER or
tpe.kind == TypeKind::REFERENCE or
tpe.kind == TypeKind::WEAK_REF or
tpe.kind == TypeKind::ARRAY) {
if tpe._tpe and tpe._tpe.kind == TypeKind::STUB and tpe._tpe.state {
tpe._tpe = box(type_lookup(tpe._tpe.node, tpe._tpe.state))
}
tpe._hash = 0
} else if tpe.kind == TypeKind::WEAK_REF {
if tpe._tpe and tpe._tpe.kind == TypeKind::STUB and tpe._tpe.state {
tpe._tpe = box(type_lookup(tpe.node.value.t_parr.tpe, tpe._tpe.state))
}
tpe._hash = 0
} else if tpe.kind == typechecking::TypeKind::STRUCT {
for var i in 0..tpe.fields.size {
let field = tpe.fields(i)
Expand Down

0 comments on commit 8cabfa9

Please sign in to comment.