code2graph 0.0.0-beta.15

Purpose-neutral code-graph extraction: source files → symbols, references, and cross-file edges. Tree-sitter based, no storage opinion.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
// SPDX-License-Identifier: Apache-2.0

//! Conformance resolver: inherited-member recall over the type hierarchy.
//!
//! This is an **additive** resolver. When a member is referenced on a type that
//! does not define it directly but **inherits or implements** it from a
//! supertype / trait / interface, this resolver links the reference to the
//! inherited definition. The link is a deterministic *structural* derivation —
//! it walks the [`RefRole::IsImplementation`] edges already produced by the
//! extractors up the type hierarchy. It is **not** type inference: no receiver
//! type is inferred, no return type is computed, no overload is resolved by
//! signature. Every edge is tagged [`Confidence::Scoped`] (structurally
//! narrowed, but not type-checked) and [`Provenance::Conformance`].
//!
//! # What it covers (the honest v1 boundary)
//!
//! Two shapes of call site are considered — never a receiver type inferred:
//!
//! - The call site **textually qualifies the owning type** — i.e. the extractor
//!   populated [`Reference::qualifier`](crate::graph::types::Reference::qualifier)
//!   with the written type name (`Foo::bar()`, `Type.method()`).
//! - The call site's receiver is the **`self` keyword** — i.e. the extractor set
//!   [`Reference::self_receiver`](crate::graph::types::Reference::self_receiver).
//!   The owning type is then read off the *enclosing* member symbol (a purely
//!   structural/syntactic fact — the call site is lexically inside that type's
//!   own method body), never inferred from a receiver's runtime or static type.
//!
//! For either shape, if the owning type does not define the member directly but
//! a supertype does, an edge is drawn to the inherited definition (first match
//! wins, walking the hierarchy depth-first).
//!
//! # What it deliberately defers (the type-inference ceiling)
//!
//! - `this.method()` / `self.method()` for languages whose extractor has not
//!   yet opted into `self_receiver` — Rust, Java, TypeScript/JavaScript, C++,
//!   Swift, C#, Kotlin, Dart, PHP, Ruby, and Scala mark it today; other
//!   languages fall back to the unqualified case above.
//! - chained `inner().method()` — needs the return type of `inner()`.
//! - field-access chains (`a.b.method()`) — needs the field's type.
//!
//! These are out of scope: code2graph stays build-free and does not infer types.
//! When neither shape applies, this resolver simply emits nothing for that
//! reference (recall is only ever *added*, never faked).

use std::borrow::Cow;
use std::collections::{HashMap, HashSet};

use crate::graph::types::{
    CodeGraph, Confidence, Edge, FileFacts, Provenance, RefRole, Symbol, SymbolKind,
};
use crate::symbol::SymbolId;

use super::Resolver;
use super::{dedup_files_last_wins, enclosing_symbol_index};

/// Inherited-member recall resolver. See module docs.
#[derive(Debug, Default, Clone, Copy)]
pub struct ConformanceResolver;

/// Whether a symbol is a *member of a type* — i.e. its descriptor chain has at
/// least two names (an owning container plus the member leaf) and its own kind
/// is a member kind (`Method`/`Const`/`Static`). For such a symbol the
/// penultimate descriptor name is the owning type and the leaf is the member.
///
/// `SymbolId` exposes descriptor *names* but not descriptor *kinds*, so the
/// symbol's own [`SymbolKind`] is the cleanest available signal that the
/// penultimate descriptor is a type (a member always renders under `Type#`).
pub(crate) fn member_of_type(sym: &Symbol) -> Option<(String /* type */, String /* member */)> {
    if !matches!(
        sym.kind,
        SymbolKind::Method | SymbolKind::Const | SymbolKind::Static | SymbolKind::Field
    ) {
        return None;
    }
    // Collect only the last two descriptor names without allocating a Vec.
    let mut second_last: Option<&str> = None;
    let mut last: Option<&str> = None;
    for name in sym.id.descriptor_names_iter() {
        second_last = last;
        last = Some(name);
    }
    match (second_last, last) {
        (Some(type_name), Some(member)) => Some((type_name.to_owned(), member.to_owned())),
        _ => None,
    }
}

impl Resolver for ConformanceResolver {
    fn resolve(&self, files: &[FileFacts]) -> crate::Result<CodeGraph> {
        crate::validate_file_facts(files)?;
        let files = dedup_files_last_wins(files);
        // ── 1. Flatten all symbols + a per-file index for caller attribution ──
        let symbols: Vec<Symbol> = files
            .iter()
            .flat_map(|f| f.symbols.iter().cloned())
            .collect();

        let mut by_file: HashMap<&str, Vec<usize>> = HashMap::new();
        for (i, s) in symbols.iter().enumerate() {
            by_file.entry(s.file.as_str()).or_default().push(i);
        }

        // ── 2. type name → { member leaf → inherited member SymbolId } ────────
        let mut members: HashMap<String, HashMap<String, SymbolId>> = HashMap::new();
        for s in &symbols {
            if let Some((type_name, member)) = member_of_type(s) {
                members
                    .entry(type_name)
                    .or_default()
                    .entry(member)
                    .or_insert_with(|| s.id.clone());
            }
        }

        // ── 3. type name → [supertype bare names] (insertion order preserved) ─
        let mut supertypes: HashMap<String, Vec<String>> = HashMap::new();
        for f in files.iter().copied() {
            for r in &f.references {
                if r.role != RefRole::IsImplementation {
                    continue;
                }
                // Relationship references may carry their written subject
                // explicitly. Extractors whose class/type symbol encloses the
                // relationship retain span attribution as a compatibility path.
                let impl_type = if let Some(subject) = r.qualifier.as_deref() {
                    subject.to_owned()
                } else {
                    let file_syms = by_file.get(f.file.as_str());
                    let Some(from_idx) = file_syms
                        .and_then(|idxs| enclosing_symbol_index(&symbols, idxs, r.occ.byte))
                    else {
                        continue;
                    };
                    let Some(subject) = symbols[from_idx].id.leaf_name() else {
                        continue;
                    };
                    subject.to_owned()
                };
                supertypes
                    .entry(impl_type)
                    .or_default()
                    .push(r.name.clone());
            }
        }

        // ── 4. emit conformance edges for type-qualified member uses ──────────
        let mut edges: Vec<Edge> = Vec::new();
        for f in files.iter().copied() {
            let file_syms = by_file.get(f.file.as_str());
            for r in &f.references {
                // Only the honest, type-qualified cases (no receiver inference),
                // plus the `self`/`this`-receiver case below (the owning type is
                // the enclosing member's own type, not a written qualifier — still
                // no receiver *type inference*, just reading the enclosing symbol).
                if !matches!(r.role, RefRole::Call | RefRole::TypeRef) {
                    continue;
                }

                // `self.method()`: derive the owning type from the enclosing
                // member symbol instead of a written qualifier. Fail closed (skip)
                // when there is no enclosing symbol or it isn't itself a type
                // member — never guess.
                let (self_enclosing_idx, type_name): (Option<usize>, Cow<'_, str>) =
                    if r.self_receiver {
                        let Some(idx) = file_syms
                            .and_then(|idxs| enclosing_symbol_index(&symbols, idxs, r.occ.byte))
                        else {
                            continue;
                        };
                        let Some((type_name, _)) = member_of_type(&symbols[idx]) else {
                            continue;
                        };
                        (Some(idx), Cow::Owned(type_name))
                    } else {
                        let Some(qualifier) = r.qualifier.as_deref() else {
                            continue; // unqualified → would need receiver-type inference
                        };
                        // The written type name is the last segment of the qualifier
                        // (`a::b::Foo` → `Foo`, `Foo` → `Foo`). Iterate directly to
                        // avoid an intermediate Vec allocation on every reference.
                        let Some(type_name) = qualifier.split(['.', '/', ':']).rfind(|s| {
                            !s.is_empty() && !matches!(*s, "." | ".." | "crate" | "self" | "super")
                        }) else {
                            continue;
                        };
                        (None, Cow::Borrowed(type_name))
                    };
                let type_name: &str = &type_name;
                let member = r.name.as_str();

                // Direct members are handled by the base resolvers — skip.
                if members
                    .get(type_name)
                    .is_some_and(|m| m.contains_key(member))
                {
                    continue;
                }

                // Walk supertypes depth-first; first ancestor defining `member`
                // wins. The visited set keeps the walk cycle-safe and stable.
                let Some(inherited) = find_inherited(type_name, member, &members, &supertypes)
                else {
                    continue;
                };

                // Attribute the edge's source to the enclosing caller symbol —
                // already resolved above for the self-receiver case.
                let Some(from_idx) = self_enclosing_idx.or_else(|| {
                    file_syms.and_then(|idxs| enclosing_symbol_index(&symbols, idxs, r.occ.byte))
                }) else {
                    continue;
                };

                edges.push(Edge {
                    from: symbols[from_idx].id.clone(),
                    to: inherited,
                    role: r.role,
                    confidence: Confidence::Scoped,
                    provenance: Provenance::Conformance,
                    occ: r.occ.clone(),
                });
            }
        }

        Ok(CodeGraph { symbols, edges })
    }
}

/// Depth-first walk up `supertypes[type_name]`, returning the inherited member's
/// [`SymbolId`] at the first ancestor type that defines `member`. Cycle-safe via
/// a visited-name set; order-stable because the supertype vectors preserve
/// insertion order and the recursion is left-to-right.
pub(crate) fn find_inherited(
    type_name: &str,
    member: &str,
    members: &HashMap<String, HashMap<String, SymbolId>>,
    supertypes: &HashMap<String, Vec<String>>,
) -> Option<SymbolId> {
    let mut visited: HashSet<String> = HashSet::new();
    visited.insert(type_name.to_owned());
    let mut stack: Vec<String> = supertypes
        .get(type_name)
        .map(|v| v.iter().rev().cloned().collect())
        .unwrap_or_default();

    while let Some(ancestor) = stack.pop() {
        if !visited.insert(ancestor.clone()) {
            continue;
        }
        if let Some(id) = members.get(&ancestor).and_then(|m| m.get(member)) {
            return Some(id.clone());
        }
        if let Some(parents) = supertypes.get(&ancestor) {
            // Push in reverse so the first-declared parent is explored first.
            for p in parents.iter().rev() {
                if !visited.contains(p) {
                    stack.push(p.clone());
                }
            }
        }
    }
    None
}

#[cfg(all(
    test,
    any(
        feature = "java",
        feature = "rust",
        feature = "typescript",
        feature = "cpp",
        feature = "swift",
        feature = "csharp",
        feature = "kotlin",
        feature = "dart",
        feature = "php",
        feature = "ruby",
        feature = "scala",
        feature = "python"
    )
))]
mod tests {
    use super::*;
    #[cfg(feature = "csharp")]
    use crate::extract::CSharpExtractor;
    #[cfg(feature = "cpp")]
    use crate::extract::CppExtractor;
    #[cfg(feature = "dart")]
    use crate::extract::DartExtractor;
    #[cfg(any(
        feature = "java",
        feature = "rust",
        feature = "typescript",
        feature = "cpp",
        feature = "swift",
        feature = "csharp",
        feature = "kotlin",
        feature = "dart",
        feature = "php",
        feature = "ruby",
        feature = "scala",
        feature = "python"
    ))]
    use crate::extract::Extractor;
    #[cfg(feature = "java")]
    use crate::extract::JavaExtractor;
    #[cfg(feature = "kotlin")]
    use crate::extract::KotlinExtractor;
    #[cfg(feature = "php")]
    use crate::extract::PhpExtractor;
    #[cfg(feature = "python")]
    use crate::extract::PythonExtractor;
    #[cfg(feature = "ruby")]
    use crate::extract::RubyExtractor;
    #[cfg(feature = "rust")]
    use crate::extract::RustExtractor;
    #[cfg(feature = "scala")]
    use crate::extract::ScalaExtractor;
    #[cfg(feature = "swift")]
    use crate::extract::SwiftExtractor;
    #[cfg(feature = "typescript")]
    use crate::extract::TypeScriptExtractor;
    #[cfg(feature = "java")]
    use crate::graph::types::{Occurrence, Reference};

    /// Build a synthetic, type-qualified member-call reference. No extractor
    /// emits a call `qualifier` yet (only Rust captures path qualifiers, and the
    /// receiver of a `Type.method()` call is not captured anywhere), so the
    /// honest v1 *input shape* — a qualified member use — is injected here, the
    /// same way the symbol-table tests inject `Import` references. The symbols
    /// and the supertype edges under test are still produced by the real
    /// extractor.
    #[cfg(feature = "java")]
    fn qualified_call(name: &str, qualifier: &str, file: &str, byte: usize) -> Reference {
        Reference {
            name: name.to_owned(),
            occ: Occurrence {
                file: file.to_owned(),
                line: 1,
                col: 0,
                byte,
            },
            role: RefRole::Call,
            source_module: None,
            from_path: None,
            is_reexport: false,
            imported_name: None,
            qualifier: Some(qualifier.to_owned()),
            scope: None,
            type_ref_ctx: None,
            cross_artifact: false,
            self_receiver: false,
        }
    }

    /// `class Base { void process(){} }`, `class Sub extends Base {}`, and a
    /// caller that qualifies `Sub.process()`. The only definition of `process`
    /// lives on `Base`, so conformance must link the call to `Base#process()`.
    #[cfg(feature = "java")]
    #[test]
    fn java_inherited_method_resolves_via_conformance() {
        let base = JavaExtractor
            .extract(
                "package p; public class Base { public void process() {} }",
                "src/p/Base.java",
            )
            .unwrap();
        let sub = JavaExtractor
            .extract(
                "package p; public class Sub extends Base {}",
                "src/p/Sub.java",
            )
            .unwrap();

        // Caller: a class whose method body holds the qualified `Sub.process()`.
        // We extract a real caller class to get a containing symbol, then inject
        // the qualified reference at a byte inside that symbol's span.
        let mut caller = JavaExtractor
            .extract(
                "package p; public class Caller { public void run() {} }",
                "src/p/Caller.java",
            )
            .unwrap();
        // Find a byte inside the `run` method symbol so the edge's `from`
        // attributes to it.
        let run = caller
            .symbols
            .iter()
            .find(|s| s.name == "run")
            .expect("run method symbol");
        let byte = run.span.start;
        caller
            .references
            .push(qualified_call("process", "Sub", "src/p/Caller.java", byte));

        let graph = ConformanceResolver.resolve(&[base, sub, caller]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();
        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge, got {:?}",
            conf_edges
                .iter()
                .map(|e| e.to.to_scip_string())
                .collect::<Vec<_>>()
        );
        let e = conf_edges[0];
        assert_eq!(e.role, RefRole::Call);
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
        assert!(
            e.to.to_scip_string().ends_with("Base#process()."),
            "edge `to` should be the inherited Base#process(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Caller#run()."),
            "edge `from` should be the enclosing caller method, got: {}",
            e.from.to_scip_string()
        );
    }

    /// Multi-level: `Sub extends Base`, `Base extends Root`, member only on
    /// `Root`. The depth-first walk must climb two levels to find it.
    #[cfg(feature = "java")]
    #[test]
    fn java_multi_level_inheritance_walks_chain() {
        let root = JavaExtractor
            .extract(
                "package p; public class Root { public void process() {} }",
                "src/p/Root.java",
            )
            .unwrap();
        let base = JavaExtractor
            .extract(
                "package p; public class Base extends Root {}",
                "src/p/Base.java",
            )
            .unwrap();
        let sub = JavaExtractor
            .extract(
                "package p; public class Sub extends Base {}",
                "src/p/Sub.java",
            )
            .unwrap();
        let mut caller = JavaExtractor
            .extract(
                "package p; public class Caller { public void run() {} }",
                "src/p/Caller.java",
            )
            .unwrap();
        let byte = caller
            .symbols
            .iter()
            .find(|s| s.name == "run")
            .expect("run symbol")
            .span
            .start;
        caller
            .references
            .push(qualified_call("process", "Sub", "src/p/Caller.java", byte));

        let graph = ConformanceResolver
            .resolve(&[root, base, sub, caller])
            .unwrap();
        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();
        assert_eq!(conf_edges.len(), 1, "expected one conformance edge");
        assert!(
            conf_edges[0]
                .to
                .to_scip_string()
                .ends_with("Root#process()."),
            "should climb two levels to Root#process(), got: {}",
            conf_edges[0].to.to_scip_string()
        );
    }

    /// A direct member called qualified on its OWN type emits no conformance
    /// edge (the base resolvers already handle direct members; we must not
    /// duplicate at `Scoped`).
    #[cfg(feature = "java")]
    #[test]
    fn direct_member_does_not_emit_conformance_edge() {
        let base = JavaExtractor
            .extract(
                "package p; public class Base { public void process() {} }",
                "src/p/Base.java",
            )
            .unwrap();
        let mut caller = JavaExtractor
            .extract(
                "package p; public class Caller { public void run() {} }",
                "src/p/Caller.java",
            )
            .unwrap();
        let byte = caller
            .symbols
            .iter()
            .find(|s| s.name == "run")
            .expect("run symbol")
            .span
            .start;
        // Qualify `Base.process()` directly on Base, which DEFINES process.
        caller
            .references
            .push(qualified_call("process", "Base", "src/p/Caller.java", byte));

        let graph = ConformanceResolver.resolve(&[base, caller]).unwrap();
        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();
        assert!(
            conf_edges.is_empty(),
            "direct member must not yield a conformance edge, got {:?}",
            conf_edges
                .iter()
                .map(|e| e.to.to_scip_string())
                .collect::<Vec<_>>()
        );
    }

    /// End-to-end proof: conformance fires on REAL Rust extraction with no injected
    /// references.  `Person::hello(p)` in main.rs uses a path-qualified call
    /// (`scoped_identifier` in tree-sitter-rust) so the extractor sets
    /// `qualifier = Some("Person")` and `name = "hello"`.  `Person` has an
    /// `IsImplementation` edge to `Greet` (from `impl Greet for Person`) so
    /// conformance walks up to `Greet` and finds `Greet#hello().` — now a real
    /// symbol thanks to the trait-member extraction added to `collect_symbols`.
    ///
    /// Static-reasoning check:
    /// - `src/greet.rs`  → symbols: `Greet` (Trait) + `Greet#hello().` (Method)
    /// - `src/person.rs` → symbol: `Person` (Struct); reference:
    ///   `IsImplementation("Greet")` with `qualifier=Some("Person")`.
    ///   The explicit relationship subject yields
    ///   `supertypes["Person"] = ["Greet"]` without minting an impl symbol.
    /// - `src/main.rs`   → Call ref `name="hello"`, `qualifier=Some("Person")`
    ///   `type_name = "Person"`, no direct `hello` member, ancestor `"Greet"` has
    ///   `hello` → conformance emits `Call` edge to `Greet#hello().`,
    ///   `Confidence::Scoped`, `Provenance::Conformance`.
    #[cfg(feature = "rust")]
    #[test]
    fn conformance_resolves_rust_inherited_trait_method_end_to_end() {
        let greet = RustExtractor
            .extract("pub trait Greet { fn hello(&self); }", "src/greet.rs")
            .unwrap();
        let person = RustExtractor
            .extract(
                "pub struct Person; impl crate::greet::Greet for Person { fn hello(&self) {} }",
                "src/person.rs",
            )
            .unwrap();
        let main = RustExtractor
            .extract(
                "pub fn run(p: &Person) { Person::hello(p); }",
                "src/main.rs",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[greet, person, main]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        // There must be at least one conformance edge whose `to` ends with
        // `Greet#hello().` — the inherited method definition on the trait.
        let to_hello: Vec<_> = conf_edges
            .iter()
            .filter(|e| e.to.to_scip_string().ends_with("Greet#hello()."))
            .collect();
        assert!(
            !to_hello.is_empty(),
            "expected a conformance edge to Greet#hello()., got conformance edges: {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = to_hello[0];
        assert_eq!(
            e.role,
            RefRole::Call,
            "edge role should be Call, got {:?}",
            e.role
        );
        assert_eq!(
            e.confidence,
            Confidence::Scoped,
            "edge confidence should be Scoped, got {:?}",
            e.confidence
        );
        assert_eq!(
            e.provenance,
            Provenance::Conformance,
            "edge provenance should be Conformance, got {:?}",
            e.provenance
        );
        // The `from` must be the enclosing `run` function in main.rs.
        assert!(
            e.from.to_scip_string().ends_with("run()."),
            "edge `from` should end with 'run().', got: {}",
            e.from.to_scip_string()
        );
    }

    /// End-to-end proof for the `self`-receiver case: `trait Greet { fn hello(&self); }`
    /// plus `impl Greet for Person { fn hello(&self){} }` (a trait impl — its body
    /// mints no `Person#hello()` symbol; the extractor only emits one for the
    /// trait's own `hello`, per `collect_trait_members`) and a separate inherent
    /// `impl Person { fn greet(&self){ self.hello(); } }` (a real `Person#greet()`
    /// symbol). `self.hello()` has no written qualifier (the extractor sets
    /// `self_receiver = true`, `qualifier = None`); the resolver must derive the
    /// owning type (`Person`) from the enclosing `greet` method, find no direct
    /// `hello` member on `Person`, walk to the supertype `Greet`, and link to
    /// `Greet#hello().`.
    #[cfg(feature = "rust")]
    #[test]
    fn conformance_resolves_rust_self_receiver_inherited_trait_method_end_to_end() {
        let greet = RustExtractor
            .extract("pub trait Greet { fn hello(&self); }", "src/greet.rs")
            .unwrap();
        let person = RustExtractor
            .extract(
                "pub struct Person; impl crate::greet::Greet for Person { fn hello(&self) {} } impl Person { fn greet(&self) { self.hello(); } }",
                "src/person.rs",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[greet, person]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the self.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Greet#hello()."),
            "edge `to` should be the inherited Greet#hello()., got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Person#greet()."),
            "edge `from` should be the enclosing Person#greet()., got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Negative: a `self.own()` call where `own` is a DIRECT member of the
    /// enclosing type (no trait involved) must NOT produce a conformance edge —
    /// the base resolvers already own direct members.
    #[cfg(feature = "rust")]
    #[test]
    fn self_receiver_direct_member_does_not_emit_conformance_edge() {
        let person = RustExtractor
            .extract(
                "pub struct Person; impl Person { fn own(&self) {} fn caller(&self) { self.own(); } }",
                "src/person.rs",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[person]).unwrap();
        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();
        assert!(
            conf_edges.is_empty(),
            "self.own() on a direct member must not yield a conformance edge, got {:?}",
            conf_edges
                .iter()
                .map(|e| e.to.to_scip_string())
                .collect::<Vec<_>>()
        );
    }

    /// `Base` defines `hello`, `Sub extends Base` calls `this.hello()` from its
    /// own method without redefining it — the only definition of `hello` is on
    /// `Base`, so conformance must link the call there. Mirrors
    /// `conformance_resolves_rust_self_receiver_inherited_trait_method_end_to_end`.
    #[cfg(feature = "java")]
    #[test]
    fn conformance_resolves_java_self_receiver_inherited_class_method_end_to_end() {
        let base = JavaExtractor
            .extract(
                "package p; public class Base { public void hello() {} }",
                "src/p/Base.java",
            )
            .unwrap();
        let sub = JavaExtractor
            .extract(
                "package p; public class Sub extends Base { public void greetAll() { this.hello(); } }",
                "src/p/Sub.java",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// TypeScript equivalent: `Base` defines `hello`, `Sub extends Base` calls
    /// `this.hello()` from its own method without redefining it. Requires TS to
    /// emit per-method `Type#method` symbols (class-member extraction) so the
    /// enclosing `Sub#greetAll` type and the inherited `Base#hello` target both
    /// exist as symbols.
    #[cfg(feature = "typescript")]
    #[test]
    fn conformance_resolves_ts_self_receiver_inherited_class_method_end_to_end() {
        let base = TypeScriptExtractor
            .extract("export class Base { hello() {} }", "src/base.ts")
            .unwrap();
        let sub = TypeScriptExtractor
            .extract(
                "import { Base } from './base'; export class Sub extends Base { greetAll() { this.hello(); } }",
                "src/sub.ts",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// JavaScript variant (shared TS core): same inheritance shape in `.js` files,
    /// proving `this.method()` self-receiver resolution flows through for JS too.
    #[cfg(feature = "typescript")]
    #[test]
    fn conformance_resolves_js_self_receiver_inherited_class_method_end_to_end() {
        use crate::extract::JavaScriptExtractor;
        let base = JavaScriptExtractor
            .extract("export class Base { hello() {} }", "src/base.js")
            .unwrap();
        let sub = JavaScriptExtractor
            .extract(
                "import { Base } from './base'; export class Sub extends Base { greetAll() { this.hello(); } }",
                "src/sub.js",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();
        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the JS this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );
        assert!(conf_edges[0].to.to_scip_string().ends_with("Base#hello()."));
        assert_eq!(conf_edges[0].confidence, Confidence::Scoped);
    }

    /// C++ variant: `Base` defines `hello`, `Sub : public Base` calls
    /// `this->hello()` from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "cpp")]
    #[test]
    fn conformance_resolves_cpp_self_receiver_inherited_class_method_end_to_end() {
        let base = CppExtractor
            .extract("class Base { public: void hello() {} };", "src/base.cpp")
            .unwrap();
        let sub = CppExtractor
            .extract(
                "class Sub : public Base { public: void greetAll() { this->hello(); } };",
                "src/sub.cpp",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this->hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Swift variant: `Base` defines `hello`, `Sub: Base` calls `self.hello()`
    /// from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "swift")]
    #[test]
    fn conformance_resolves_swift_self_receiver_inherited_class_method_end_to_end() {
        let base = SwiftExtractor
            .extract("class Base { func hello() {} }", "Sources/Base.swift")
            .unwrap();
        let sub = SwiftExtractor
            .extract(
                "class Sub: Base { func greetAll() { self.hello() } }",
                "Sources/Sub.swift",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the self.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// C# variant: `Base` defines `Hello`, `Sub : Base` calls `this.Hello()`
    /// from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "csharp")]
    #[test]
    fn conformance_resolves_csharp_self_receiver_inherited_class_method_end_to_end() {
        let base = CSharpExtractor
            .extract(
                "public class Base { public void Hello() {} }",
                "src/Base.cs",
            )
            .unwrap();
        let sub = CSharpExtractor
            .extract(
                "public class Sub : Base { public void GreetAll() { this.Hello(); } }",
                "src/Sub.cs",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.Hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#Hello()."),
            "edge `to` should be the inherited Base#Hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#GreetAll()."),
            "edge `from` should be the enclosing Sub#GreetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Kotlin variant: `Base` defines `hello`, `Sub : Base()` calls
    /// `this.hello()` from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "kotlin")]
    #[test]
    fn conformance_resolves_kotlin_self_receiver_inherited_class_method_end_to_end() {
        let base = KotlinExtractor
            .extract("open class Base { open fun hello() {} }", "src/Base.kt")
            .unwrap();
        let sub = KotlinExtractor
            .extract(
                "class Sub : Base() { fun greetAll() { this.hello() } }",
                "src/Sub.kt",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Dart variant: `Base` defines `hello`, `Sub extends Base` calls
    /// `this.hello()` from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "dart")]
    #[test]
    fn conformance_resolves_dart_self_receiver_inherited_class_method_end_to_end() {
        let base = DartExtractor
            .extract("class Base { void hello() {} }", "lib/base.dart")
            .unwrap();
        let sub = DartExtractor
            .extract(
                "class Sub extends Base { void greetAll() { this.hello(); } }",
                "lib/sub.dart",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// PHP variant: `Base` defines `hello`, `Sub extends Base` calls
    /// `$this->hello()` from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "php")]
    #[test]
    fn conformance_resolves_php_self_receiver_inherited_class_method_end_to_end() {
        let base = PhpExtractor
            .extract(
                "<?php\nclass Base { public function hello() {} }\n",
                "src/Base.php",
            )
            .unwrap();
        let sub = PhpExtractor
            .extract(
                "<?php\nclass Sub extends Base { public function greetAll() { $this->hello(); } }\n",
                "src/Sub.php",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the $this->hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Ruby variant: `Base` defines `hello`, `Sub < Base` calls `self.hello`
    /// from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "ruby")]
    #[test]
    fn conformance_resolves_ruby_self_receiver_inherited_class_method_end_to_end() {
        let base = RubyExtractor
            .extract("class Base\n  def hello\n  end\nend\n", "lib/base.rb")
            .unwrap();
        let sub = RubyExtractor
            .extract(
                "class Sub < Base\n  def greet_all\n    self.hello\n  end\nend\n",
                "lib/sub.rb",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the self.hello site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greet_all()."),
            "edge `from` should be the enclosing Sub#greet_all(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Scala variant: `Base` defines `hello`, `Sub extends Base` calls
    /// `this.hello()` from its own method without redefining it. Mirrors
    /// `conformance_resolves_java_self_receiver_inherited_class_method_end_to_end`.
    #[cfg(feature = "scala")]
    #[test]
    fn conformance_resolves_scala_self_receiver_inherited_class_method_end_to_end() {
        let base = ScalaExtractor
            .extract("class Base { def hello(): Unit = {} }", "src/Base.scala")
            .unwrap();
        let sub = ScalaExtractor
            .extract(
                "class Sub extends Base { def greetAll(): Unit = { this.hello() } }",
                "src/Sub.scala",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the this.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greetAll()."),
            "edge `from` should be the enclosing Sub#greetAll(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// Python equivalent: `Base` defines `hello`, `Sub(Base)` calls `self.hello()`
    /// from its own method. Python's `self` is a naming convention (a plain
    /// identifier), resolved via the text-gated self-receiver query.
    #[cfg(feature = "python")]
    #[test]
    fn conformance_resolves_python_self_receiver_inherited_class_method_end_to_end() {
        let base = PythonExtractor
            .extract(
                "class Base:\n    def hello(self):\n        pass\n",
                "src/base.py",
            )
            .unwrap();
        let sub = PythonExtractor
            .extract(
                "from base import Base\n\nclass Sub(Base):\n    def greet_all(self):\n        self.hello()\n",
                "src/sub.py",
            )
            .unwrap();

        let graph = ConformanceResolver.resolve(&[base, sub]).unwrap();

        let conf_edges: Vec<_> = graph
            .edges
            .iter()
            .filter(|e| e.provenance == Provenance::Conformance)
            .collect();

        assert_eq!(
            conf_edges.len(),
            1,
            "expected exactly one conformance edge for the self.hello() site, got {:?}",
            conf_edges
                .iter()
                .map(|e| format!("{} -> {}", e.from.to_scip_string(), e.to.to_scip_string()))
                .collect::<Vec<_>>()
        );

        let e = conf_edges[0];
        assert!(
            e.to.to_scip_string().ends_with("Base#hello()."),
            "edge `to` should be the inherited Base#hello(), got: {}",
            e.to.to_scip_string()
        );
        assert!(
            e.from.to_scip_string().ends_with("Sub#greet_all()."),
            "edge `from` should be the enclosing Sub#greet_all(), got: {}",
            e.from.to_scip_string()
        );
        assert_eq!(e.confidence, Confidence::Scoped);
        assert_eq!(e.provenance, Provenance::Conformance);
    }

    /// An unqualified reference (no receiver type written) is deferred entirely:
    /// resolving it would need receiver-type inference, which v1 does not do.
    #[cfg(feature = "java")]
    #[test]
    fn unqualified_reference_is_deferred() {
        let base = JavaExtractor
            .extract(
                "package p; public class Base { public void process() {} }",
                "src/p/Base.java",
            )
            .unwrap();
        let sub = JavaExtractor
            .extract(
                "package p; public class Sub extends Base {}",
                "src/p/Sub.java",
            )
            .unwrap();
        let mut caller = JavaExtractor
            .extract(
                "package p; public class Caller { public void run() {} }",
                "src/p/Caller.java",
            )
            .unwrap();
        let byte = caller
            .symbols
            .iter()
            .find(|s| s.name == "run")
            .expect("run symbol")
            .span
            .start;
        // No qualifier → must be skipped.
        let mut unq = qualified_call("process", "Sub", "src/p/Caller.java", byte);
        unq.qualifier = None;
        caller.references.push(unq);

        let graph = ConformanceResolver.resolve(&[base, sub, caller]).unwrap();
        assert!(
            graph
                .edges
                .iter()
                .all(|e| e.provenance != Provenance::Conformance),
            "unqualified ref must not produce a conformance edge"
        );
    }
}