fix: don't check context of field accesses' target (#1039)

This commit is contained in:
Myriad-Dreamin 2024-12-21 13:23:21 +08:00 committed by GitHub
parent 6d36195964
commit 1c157adadf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -182,15 +182,20 @@ impl<'a> PostTypeChecker<'a> {
None
};
let contextual_self_ty =
self.check_cursor(classify_context(node.clone(), None), context_ty);
let can_penetrate_context = !(matches!(context.kind(), SyntaxKind::FieldAccess) && {
let field_access = context.cast::<ast::FieldAccess>()?;
field_access.field().span() == node.span()
});
let contextual_self_ty = can_penetrate_context
.then(|| self.check_cursor(classify_context(node.clone(), None), context_ty));
crate::log_debug_ct!(
"post check(res): {:?}::{:?} -> {self_ty:?}, {contextual_self_ty:?}",
context.kind(),
node.kind(),
);
Ty::union(self_ty, contextual_self_ty)
Ty::union(self_ty, contextual_self_ty.flatten())
}
fn check_or(&mut self, node: &LinkedNode, ty: Option<Ty>) -> Option<Ty> {