@@ -193,20 +193,15 @@ static void py_disable_callable_value_proof(PyLSPContext *ctx) {
193193
194194static void py_scope_bind (PyLSPContext * ctx , const char * name , const CBMType * type ) {
195195 ctx -> type_cache_gen ++ ;
196- cbm_scope_bind (ctx -> current_scope , name , type );
197- if (name && !cbm_scope_contains (ctx -> current_scope , name ))
196+ if (!cbm_scope_bind_checked (ctx -> current_scope , name , type ))
198197 py_disable_callable_value_proof (ctx );
199198}
200199
201200static void py_scope_bind_callable (PyLSPContext * ctx , const char * name , const CBMType * type ,
202201 const char * callable_qn ) {
203202 ctx -> type_cache_gen ++ ;
204- cbm_scope_bind_callable (ctx -> current_scope , name , type , callable_qn );
205- const char * bound = name ? cbm_scope_lookup_callable (ctx -> current_scope , name ) : NULL ;
206- if (name && (!cbm_scope_contains (ctx -> current_scope , name ) ||
207- (callable_qn && (!bound || strcmp (bound , callable_qn ) != 0 )))) {
203+ if (!cbm_scope_bind_callable_checked (ctx -> current_scope , name , type , callable_qn ))
208204 py_disable_callable_value_proof (ctx );
209- }
210205}
211206
212207static CBMScope * py_scope_push_checked (PyLSPContext * ctx ) {
@@ -945,8 +940,9 @@ static const char *py_exact_callable_target_ex(PyLSPContext *ctx, TSNode node,
945940 char * name = py_node_text (ctx , node );
946941 if (!name )
947942 return NULL ;
948- if (cbm_scope_contains (ctx -> current_scope , name )) {
949- const char * bound = cbm_scope_lookup_callable (ctx -> current_scope , name );
943+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , name );
944+ if (binding ) {
945+ const char * bound = binding -> callable_qn ;
950946 if (bound && lexical_alias_out ) {
951947 /* A lexical binding that does NOT simply name the module symbol
952948 * of the same spelling is an alias introduced in this body. Only
@@ -1025,12 +1021,13 @@ static void py_resolve_value_references_at(PyLSPContext *ctx, TSNode call) {
10251021 const char * candidate = strcmp (kind , "identifier" ) == 0
10261022 ? py_exact_imported_reference_candidate (ctx , source_name )
10271023 : NULL ;
1028- if (candidate && cbm_scope_contains (ctx -> current_scope , source_name )) {
1029- const CBMType * binding =
1030- cbm_type_resolve_alias (cbm_scope_lookup (ctx -> current_scope , source_name ));
1031- if (binding && binding -> kind == CBM_TYPE_NAMED &&
1032- binding -> data .named .qualified_name &&
1033- strcmp (binding -> data .named .qualified_name , candidate ) == 0 ) {
1024+ const CBMVarBinding * scope_binding =
1025+ candidate ? cbm_scope_lookup_binding (ctx -> current_scope , source_name ) : NULL ;
1026+ if (scope_binding ) {
1027+ const CBMType * type = cbm_type_resolve_alias (scope_binding -> type );
1028+ if (type && type -> kind == CBM_TYPE_NAMED &&
1029+ type -> data .named .qualified_name &&
1030+ strcmp (type -> data .named .qualified_name , candidate ) == 0 ) {
10341031 py_emit_unresolved_reference (ctx , candidate , arg );
10351032 }
10361033 }
@@ -1512,9 +1509,9 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
15121509 char * name = py_node_text (ctx , node );
15131510 if (!name )
15141511 return cbm_type_unknown ();
1515- const CBMType * t = cbm_scope_lookup (ctx -> current_scope , name );
1516- if (cbm_scope_contains ( ctx -> current_scope , name ) )
1517- return t ? t : cbm_type_unknown ();
1512+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , name );
1513+ if (binding )
1514+ return binding -> type ? binding -> type : cbm_type_unknown ();
15181515 // Builtin globals: True / False / None at top level.
15191516 if (strcmp (name , "True" ) == 0 || strcmp (name , "False" ) == 0 )
15201517 return cbm_type_builtin (ctx -> arena , "bool" );
@@ -1780,8 +1777,11 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
17801777 }
17811778 }
17821779 // Constructor call: ClassName() returns NAMED(ClassName).
1783- const CBMType * in_scope = cbm_scope_lookup (ctx -> current_scope , fname );
1784- const char * callable_qn = cbm_scope_lookup_callable (ctx -> current_scope , fname );
1780+ const CBMVarBinding * binding =
1781+ cbm_scope_lookup_binding (ctx -> current_scope , fname );
1782+ const CBMType * in_scope =
1783+ binding && binding -> type ? binding -> type : cbm_type_unknown ();
1784+ const char * callable_qn = binding ? binding -> callable_qn : NULL ;
17851785 if (callable_qn ) {
17861786 return py_func_return_type (ctx , callable_qn );
17871787 }
@@ -1809,7 +1809,7 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
18091809 }
18101810 /* Even an UNKNOWN local/parameter is a real lexical shadow. Do
18111811 * not borrow the return type of a same-named module function. */
1812- if (cbm_scope_contains ( ctx -> current_scope , fname ) )
1812+ if (binding )
18131813 return cbm_type_unknown ();
18141814 // Module-local function call.
18151815 const CBMRegisteredFunc * f =
@@ -2579,14 +2579,16 @@ static void py_emit_call_for(PyLSPContext *ctx, TSNode call_node) {
25792579 * An ordinary local binding is also a hard shadow: if it is not a
25802580 * proven callable alias, do not fall through and fabricate a direct
25812581 * call to a module-level function with the same spelling. */
2582- if (cbm_scope_contains (ctx -> current_scope , fname )) {
2583- const char * alias_target = cbm_scope_lookup_callable (ctx -> current_scope , fname );
2582+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , fname );
2583+ if (binding ) {
2584+ const char * alias_target = binding -> callable_qn ;
25842585 if (alias_target ) {
25852586 py_emit_resolved_call_reason (ctx , alias_target , "lsp_callable_alias" , 0.97f , fname ,
25862587 call_node );
25872588 return ;
25882589 }
2589- const CBMType * in_scope = cbm_scope_lookup (ctx -> current_scope , fname );
2590+ const CBMType * in_scope =
2591+ binding -> type ? binding -> type : cbm_type_unknown ();
25902592 if (!cbm_type_is_unknown (in_scope ) && in_scope -> kind == CBM_TYPE_NAMED ) {
25912593 const char * qn = in_scope -> data .named .qualified_name ;
25922594 const char * tail = qn ? strrchr (qn , '.' ) : NULL ;
@@ -2618,13 +2620,6 @@ static void py_emit_call_for(PyLSPContext *ctx, TSNode call_node) {
26182620 }
26192621 return ;
26202622 }
2621- // Constructor call (ClassName())
2622- const CBMType * in_scope = cbm_scope_lookup (ctx -> current_scope , fname );
2623- if (!cbm_type_is_unknown (in_scope ) && in_scope -> kind == CBM_TYPE_NAMED ) {
2624- const char * qn = in_scope -> data .named .qualified_name ;
2625- py_emit_resolved_call (ctx , qn , "lsp_constructor" , 0.85f , call_node );
2626- return ;
2627- }
26282623 // Module-local function
26292624 const CBMRegisteredFunc * f =
26302625 cbm_registry_lookup_symbol (ctx -> registry , ctx -> module_qn , fname );
0 commit comments