@@ -191,20 +191,15 @@ static void py_disable_callable_value_proof(PyLSPContext *ctx) {
191191
192192static void py_scope_bind (PyLSPContext * ctx , const char * name , const CBMType * type ) {
193193 ctx -> type_cache_gen ++ ;
194- cbm_scope_bind (ctx -> current_scope , name , type );
195- if (name && !cbm_scope_contains (ctx -> current_scope , name ))
194+ if (!cbm_scope_bind_checked (ctx -> current_scope , name , type ))
196195 py_disable_callable_value_proof (ctx );
197196}
198197
199198static void py_scope_bind_callable (PyLSPContext * ctx , const char * name , const CBMType * type ,
200199 const char * callable_qn ) {
201200 ctx -> type_cache_gen ++ ;
202- cbm_scope_bind_callable (ctx -> current_scope , name , type , callable_qn );
203- const char * bound = name ? cbm_scope_lookup_callable (ctx -> current_scope , name ) : NULL ;
204- if (name && (!cbm_scope_contains (ctx -> current_scope , name ) ||
205- (callable_qn && (!bound || strcmp (bound , callable_qn ) != 0 )))) {
201+ if (!cbm_scope_bind_callable_checked (ctx -> current_scope , name , type , callable_qn ))
206202 py_disable_callable_value_proof (ctx );
207- }
208203}
209204
210205static CBMScope * py_scope_push_checked (PyLSPContext * ctx ) {
@@ -938,8 +933,9 @@ static const char *py_exact_callable_target_ex(PyLSPContext *ctx, TSNode node,
938933 char * name = py_node_text (ctx , node );
939934 if (!name )
940935 return NULL ;
941- if (cbm_scope_contains (ctx -> current_scope , name )) {
942- const char * bound = cbm_scope_lookup_callable (ctx -> current_scope , name );
936+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , name );
937+ if (binding ) {
938+ const char * bound = binding -> callable_qn ;
943939 if (bound && lexical_alias_out ) {
944940 /* A lexical binding that does NOT simply name the module symbol
945941 * of the same spelling is an alias introduced in this body. Only
@@ -1018,11 +1014,12 @@ static void py_resolve_value_references_at(PyLSPContext *ctx, TSNode call) {
10181014 const char * candidate = strcmp (kind , "identifier" ) == 0
10191015 ? py_exact_imported_reference_candidate (ctx , source_name )
10201016 : NULL ;
1021- if (candidate && cbm_scope_contains (ctx -> current_scope , source_name )) {
1022- const CBMType * binding =
1023- cbm_type_resolve_alias (cbm_scope_lookup (ctx -> current_scope , source_name ));
1024- if (binding && binding -> kind == CBM_TYPE_NAMED && binding -> data .named .qualified_name &&
1025- strcmp (binding -> data .named .qualified_name , candidate ) == 0 ) {
1017+ const CBMVarBinding * scope_binding =
1018+ candidate ? cbm_scope_lookup_binding (ctx -> current_scope , source_name ) : NULL ;
1019+ if (scope_binding ) {
1020+ const CBMType * type = cbm_type_resolve_alias (scope_binding -> type );
1021+ if (type && type -> kind == CBM_TYPE_NAMED && type -> data .named .qualified_name &&
1022+ strcmp (type -> data .named .qualified_name , candidate ) == 0 ) {
10261023 py_emit_unresolved_reference (ctx , candidate , arg );
10271024 }
10281025 }
@@ -1498,9 +1495,9 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
14981495 char * name = py_node_text (ctx , node );
14991496 if (!name )
15001497 return cbm_type_unknown ();
1501- const CBMType * t = cbm_scope_lookup (ctx -> current_scope , name );
1502- if (cbm_scope_contains ( ctx -> current_scope , name ) )
1503- return t ? t : cbm_type_unknown ();
1498+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , name );
1499+ if (binding )
1500+ return binding -> type ? binding -> type : cbm_type_unknown ();
15041501 // Builtin globals: True / False / None at top level.
15051502 if (strcmp (name , "True" ) == 0 || strcmp (name , "False" ) == 0 )
15061503 return cbm_type_builtin (ctx -> arena , "bool" );
@@ -1767,8 +1764,9 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
17671764 }
17681765 }
17691766 // Constructor call: ClassName() returns NAMED(ClassName).
1770- const CBMType * in_scope = cbm_scope_lookup (ctx -> current_scope , fname );
1771- const char * callable_qn = cbm_scope_lookup_callable (ctx -> current_scope , fname );
1767+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , fname );
1768+ const CBMType * in_scope = binding && binding -> type ? binding -> type : cbm_type_unknown ();
1769+ const char * callable_qn = binding ? binding -> callable_qn : NULL ;
17721770 if (callable_qn ) {
17731771 return py_func_return_type (ctx , callable_qn );
17741772 }
@@ -1796,7 +1794,7 @@ static const CBMType *py_eval_expr_type_uncached(PyLSPContext *ctx, TSNode node)
17961794 }
17971795 /* Even an UNKNOWN local/parameter is a real lexical shadow. Do
17981796 * not borrow the return type of a same-named module function. */
1799- if (cbm_scope_contains ( ctx -> current_scope , fname ) )
1797+ if (binding )
18001798 return cbm_type_unknown ();
18011799 // Module-local function call.
18021800 const CBMRegisteredFunc * f =
@@ -2566,14 +2564,15 @@ static void py_emit_call_for(PyLSPContext *ctx, TSNode call_node) {
25662564 * An ordinary local binding is also a hard shadow: if it is not a
25672565 * proven callable alias, do not fall through and fabricate a direct
25682566 * call to a module-level function with the same spelling. */
2569- if (cbm_scope_contains (ctx -> current_scope , fname )) {
2570- const char * alias_target = cbm_scope_lookup_callable (ctx -> current_scope , fname );
2567+ const CBMVarBinding * binding = cbm_scope_lookup_binding (ctx -> current_scope , fname );
2568+ if (binding ) {
2569+ const char * alias_target = binding -> callable_qn ;
25712570 if (alias_target ) {
25722571 py_emit_resolved_call_reason (ctx , alias_target , "lsp_callable_alias" , 0.97f , fname ,
25732572 call_node );
25742573 return ;
25752574 }
2576- const CBMType * in_scope = cbm_scope_lookup ( ctx -> current_scope , fname );
2575+ const CBMType * in_scope = binding -> type ? binding -> type : cbm_type_unknown ( );
25772576 if (!cbm_type_is_unknown (in_scope ) && in_scope -> kind == CBM_TYPE_NAMED ) {
25782577 const char * qn = in_scope -> data .named .qualified_name ;
25792578 const char * tail = qn ? strrchr (qn , '.' ) : NULL ;
@@ -2604,13 +2603,6 @@ static void py_emit_call_for(PyLSPContext *ctx, TSNode call_node) {
26042603 }
26052604 return ;
26062605 }
2607- // Constructor call (ClassName())
2608- const CBMType * in_scope = cbm_scope_lookup (ctx -> current_scope , fname );
2609- if (!cbm_type_is_unknown (in_scope ) && in_scope -> kind == CBM_TYPE_NAMED ) {
2610- const char * qn = in_scope -> data .named .qualified_name ;
2611- py_emit_resolved_call (ctx , qn , "lsp_constructor" , 0.85f , call_node );
2612- return ;
2613- }
26142606 // Module-local function
26152607 const CBMRegisteredFunc * f =
26162608 cbm_registry_lookup_symbol (ctx -> registry , ctx -> module_qn , fname );
0 commit comments