@@ -5,6 +5,7 @@ mod ref_type;
55mod simple_type;
66mod sub_type;
77mod test;
8+ mod type_check_context;
89mod type_check_fail_reason;
910mod type_check_guard;
1011
@@ -16,7 +17,10 @@ use simple_type::check_simple_type_compact;
1617pub use type_check_fail_reason:: TypeCheckFailReason ;
1718use type_check_guard:: TypeCheckGuard ;
1819
19- use crate :: db_index:: { DbIndex , LuaType } ;
20+ use crate :: {
21+ db_index:: { DbIndex , LuaType } ,
22+ semantic:: type_check:: type_check_context:: TypeCheckContext ,
23+ } ;
2024pub use sub_type:: is_sub_type_of;
2125pub type TypeCheckResult = Result < ( ) , TypeCheckFailReason > ;
2226
@@ -25,21 +29,32 @@ pub fn check_type_compact(
2529 source : & LuaType ,
2630 compact_type : & LuaType ,
2731) -> TypeCheckResult {
28- check_general_type_compact ( db, source, compact_type, TypeCheckGuard :: new ( ) )
32+ let context = TypeCheckContext :: new ( db, false ) ;
33+ check_general_type_compact ( & context, source, compact_type, TypeCheckGuard :: new ( ) )
2934}
3035
31- fn check_general_type_compact (
36+ pub fn check_type_compact_detail (
3237 db : & DbIndex ,
3338 source : & LuaType ,
3439 compact_type : & LuaType ,
40+ ) -> TypeCheckResult {
41+ let guard = TypeCheckGuard :: new ( ) ;
42+ let context = TypeCheckContext :: new ( db, true ) ;
43+ check_general_type_compact ( & context, source, compact_type, guard)
44+ }
45+
46+ fn check_general_type_compact (
47+ context : & TypeCheckContext ,
48+ source : & LuaType ,
49+ compact_type : & LuaType ,
3550 check_guard : TypeCheckGuard ,
3651) -> TypeCheckResult {
3752 if is_like_any ( compact_type) {
3853 return Ok ( ( ) ) ;
3954 }
4055
41- if let Some ( origin_type) = escape_type ( db, compact_type) {
42- return check_general_type_compact ( db , source, & origin_type, check_guard. next_level ( ) ?) ;
56+ if let Some ( origin_type) = escape_type ( & context . db , compact_type) {
57+ return check_general_type_compact ( context , source, & origin_type, check_guard. next_level ( ) ?) ;
4358 }
4459
4560 match source {
@@ -69,24 +84,24 @@ fn check_general_type_compact(
6984 | LuaType :: ConstTplRef ( _)
7085 | LuaType :: Namespace ( _)
7186 | LuaType :: Variadic ( _)
72- | LuaType :: Language ( _) => check_simple_type_compact ( db , source, compact_type, check_guard) ,
87+ | LuaType :: Language ( _) => check_simple_type_compact ( context , source, compact_type, check_guard) ,
7388
7489 // type ref
7590 LuaType :: Ref ( type_decl_id) => {
76- check_ref_type_compact ( db , type_decl_id, compact_type, check_guard)
91+ check_ref_type_compact ( context , type_decl_id, compact_type, check_guard)
7792 }
7893 LuaType :: Def ( type_decl_id) => {
79- check_ref_type_compact ( db , type_decl_id, compact_type, check_guard)
94+ check_ref_type_compact ( context , type_decl_id, compact_type, check_guard)
8095 }
8196 // invaliad source type
8297 // LuaType::Module(arc_intern) => todo!(),
8398
8499 // function type
85100 LuaType :: DocFunction ( doc_func) => {
86- check_doc_func_type_compact ( db , doc_func, compact_type, check_guard)
101+ check_doc_func_type_compact ( context , doc_func, compact_type, check_guard)
87102 }
88103 // signature type
89- LuaType :: Signature ( sig_id) => check_sig_type_compact ( db , sig_id, compact_type, check_guard) ,
104+ LuaType :: Signature ( sig_id) => check_sig_type_compact ( context , sig_id, compact_type, check_guard) ,
90105
91106 // complex type
92107 LuaType :: Array ( _)
@@ -96,20 +111,20 @@ fn check_general_type_compact(
96111 | LuaType :: Intersection ( _)
97112 | LuaType :: TableGeneric ( _)
98113 | LuaType :: MultiLineUnion ( _) => {
99- check_complex_type_compact ( db , source, compact_type, check_guard)
114+ check_complex_type_compact ( dcontext , source, compact_type, check_guard)
100115 }
101116
102117 // need think how to do that
103118 LuaType :: Call ( _) => Ok ( ( ) ) ,
104119
105120 // generic type
106121 LuaType :: Generic ( generic) => {
107- check_generic_type_compact ( db , generic, compact_type, check_guard)
122+ check_generic_type_compact ( context , generic, compact_type, check_guard)
108123 }
109124 // invalid source type
110125 // LuaType::MemberPathExist(_) |
111126 LuaType :: Instance ( instantiate) => check_general_type_compact (
112- db ,
127+ context ,
113128 instantiate. get_base ( ) ,
114129 compact_type,
115130 check_guard. next_level ( ) ?,
@@ -127,7 +142,11 @@ fn check_general_type_compact(
127142fn is_like_any ( ty : & LuaType ) -> bool {
128143 matches ! (
129144 ty,
130- LuaType :: Any | LuaType :: Unknown | LuaType :: TplRef ( _) | LuaType :: StrTplRef ( _)
145+ LuaType :: Any
146+ | LuaType :: Unknown
147+ | LuaType :: TplRef ( _)
148+ | LuaType :: StrTplRef ( _)
149+ | LuaType :: ConstTplRef ( _)
131150 )
132151}
133152
0 commit comments