@@ -24,24 +24,26 @@ struct LinkResolution
24
24
{
25
25
var tables : SSGC . Linker . Tables = . init( )
26
26
27
- tables. packageLinks [ " ThisModule " , . init( [ " A " ] , " b " ) ] . append ( . init(
28
- phylum: . func( . instance) ,
29
- kinks: [ ] ,
27
+ tables. packageLinks [ " ThisModule " , . init( [ " A " ] , " b " ) ] . append ( . init( traits: . init(
28
+ autograph: nil ,
29
+ phylum: . func( . instance) ,
30
+ kinks: [ ] ,
31
+ hash: . init( hashing: " x " ) ) ,
30
32
decl: 0 ,
31
33
heir: nil ,
32
- hash: . init( hashing: " x " ) ,
33
34
documented: true ,
34
- autograph : nil ,
35
+ inherited : false ,
35
36
id: " x " ) )
36
37
37
- tables. packageLinks [ " ThisModule " , . init( [ " A " ] , " c " ) ] . append ( . init(
38
- phylum: . func( . instance) ,
39
- kinks: [ ] ,
38
+ tables. packageLinks [ " ThisModule " , . init( [ " A " ] , " c " ) ] . append ( . init( traits: . init(
39
+ autograph: nil ,
40
+ phylum: . func( . instance) ,
41
+ kinks: [ ] ,
42
+ hash: . init( hashing: " y " ) ) ,
40
43
decl: 1 ,
41
44
heir: nil ,
42
- hash: . init( hashing: " y " ) ,
43
45
documented: true ,
44
- autograph : nil ,
46
+ inherited : false ,
45
47
id: " y " ) )
46
48
47
49
// Unscoped tests
@@ -87,24 +89,26 @@ struct LinkResolution
87
89
{
88
90
var tables : SSGC . Linker . Tables = . init( )
89
91
90
- tables. packageLinks [ " OtherModule " , . init( [ " A " ] , " b " ) ] . append ( . init(
91
- phylum: . func( . instance) ,
92
- kinks: [ ] ,
92
+ tables. packageLinks [ " OtherModule " , . init( [ " A " ] , " b " ) ] . append ( . init( traits: . init(
93
+ autograph: nil ,
94
+ phylum: . func( . instance) ,
95
+ kinks: [ ] ,
96
+ hash: . init( hashing: " x " ) ) ,
93
97
decl: 0 ,
94
98
heir: nil ,
95
- hash: . init( hashing: " x " ) ,
96
99
documented: true ,
97
- autograph : nil ,
100
+ inherited : false ,
98
101
id: " x " ) )
99
102
100
- tables. packageLinks [ " OtherModule " , . init( [ " A " ] , " c " ) ] . append ( . init(
101
- phylum: . func( . instance) ,
102
- kinks: [ ] ,
103
+ tables. packageLinks [ " OtherModule " , . init( [ " A " ] , " c " ) ] . append ( . init( traits: . init(
104
+ autograph: nil ,
105
+ phylum: . func( . instance) ,
106
+ kinks: [ ] ,
107
+ hash: . init( hashing: " y " ) ) ,
103
108
decl: 1 ,
104
109
heir: nil ,
105
- hash: . init( hashing: " y " ) ,
106
110
documented: true ,
107
- autograph : nil ,
111
+ inherited : false ,
108
112
id: " y " ) )
109
113
110
114
// Without registering modules, these symbols should be invisible to the resolver.
@@ -215,14 +219,15 @@ struct LinkResolution
215
219
] . enumerated ( )
216
220
{
217
221
let id : Symbol . Decl = . init( . s, ascii: " \( i) " )
218
- tables. packageLinks [ " ThisModule " , . init( [ " A " ] , name) ] . append ( . init(
219
- phylum: . func( . instance) ,
220
- kinks: [ ] ,
222
+ tables. packageLinks [ " ThisModule " , . init( [ " A " ] , name) ] . append ( . init( traits: . init(
223
+ autograph: . init( inputs: inputs, output: output) ,
224
+ phylum: . func( . instance) ,
225
+ kinks: [ ] ,
226
+ hash: . init( hashing: " \( id) " ) ) ,
221
227
decl: Int32 . init ( i) ,
222
228
heir: nil ,
223
- hash: . init( hashing: " \( id) " ) ,
224
229
documented: true ,
225
- autograph : . init ( inputs : inputs , output : output ) ,
230
+ inherited : false ,
226
231
id: id) )
227
232
}
228
233
@@ -277,14 +282,15 @@ struct LinkResolution
277
282
] . enumerated ( )
278
283
{
279
284
let id : Symbol . Decl = . init( . s, ascii: " \( i) " )
280
- tables. packageLinks [ " ThisModule " , . init( [ " A " ] , name) ] . append ( . init(
281
- phylum: . func( . instance) ,
282
- kinks: kinks,
285
+ tables. packageLinks [ " ThisModule " , . init( [ " A " ] , name) ] . append ( . init( traits: . init(
286
+ autograph: . init( inputs: inputs, output: output) ,
287
+ phylum: . func( . instance) ,
288
+ kinks: kinks,
289
+ hash: . init( hashing: " \( id) " ) ) ,
283
290
decl: Int32 . init ( i) ,
284
291
heir: nil ,
285
- hash: . init( hashing: " \( id) " ) ,
286
292
documented: true ,
287
- autograph : . init ( inputs : inputs , output : output ) ,
293
+ inherited : false ,
288
294
id: id) )
289
295
}
290
296
@@ -327,4 +333,78 @@ struct LinkResolution
327
333
] )
328
334
}
329
335
}
336
+ @Test
337
+ static func Preference( )
338
+ {
339
+ var tables : SSGC . Linker . Tables = . init( )
340
+
341
+ for (i, ( name, ( documented, inherited) , kinks) ) :
342
+ ( Int , ( String , ( Bool , Bool ) , Phylum . Decl . Kinks ) ) in [
343
+ ( " f(_:) " , ( false , false ) , [ ] ) ,
344
+ ( " f(_:) " , ( false , true ) , [ ] ) ,
345
+
346
+ ( " g(_:) " , ( true , false ) , [ ] ) ,
347
+ ( " g(_:) " , ( false , false ) , [ ] ) ,
348
+
349
+ // We should always prefer a symbol that is not inherited, even if it lacks
350
+ // documentation and the inherited symbol has it.
351
+ ( " h(_:) " , ( true , true ) , [ ] ) ,
352
+ ( " h(_:) " , ( false , true ) , [ ] ) ,
353
+ ( " h(_:) " , ( false , false ) , [ ] ) ,
354
+
355
+ // Inherited symbols with documentation should never cause a conflict.
356
+ ( " i(_:) " , ( true , true ) , [ ] ) ,
357
+ ( " i(_:) " , ( false , true ) , [ ] ) ,
358
+ ( " i(_:) " , ( false , false ) , [ ] ) ,
359
+ ( " i(_:) " , ( true , false ) , [ ] ) ,
360
+
361
+ ( " w(_:) " , ( true , true ) , [ ] ) ,
362
+ ( " w(_:) " , ( true , true ) , [ ] ) ,
363
+
364
+ ( " x(_:) " , ( true , false ) , [ ] ) ,
365
+ ( " x(_:) " , ( true , false ) , [ ] ) ,
366
+
367
+ ( " y(_:) " , ( false , false ) , [ ] ) ,
368
+ ( " y(_:) " , ( false , false ) , [ ] ) ,
369
+
370
+ ( " z(_:) " , ( false , true ) , [ ] ) ,
371
+ ( " z(_:) " , ( false , true ) , [ ] ) ,
372
+ ] . enumerated ( )
373
+ {
374
+ let id : Symbol . Decl = . init( . s, ascii: " \( i) " )
375
+ tables. packageLinks [ " ThisModule " , . init( [ " A " ] , name) ] . append ( . init( traits: . init(
376
+ autograph: . init( inputs: [ " Int " ] , output: [ ] ) ,
377
+ phylum: . func( . instance) ,
378
+ kinks: kinks,
379
+ hash: . init( hashing: " \( id) " ) ) ,
380
+ decl: Int32 . init ( i) ,
381
+ heir: nil ,
382
+ documented: documented,
383
+ inherited: inherited,
384
+ id: id) )
385
+ }
386
+
387
+ tables. resolving ( with: . init( origin: nil ,
388
+ namespace: nil ,
389
+ context: . init( id: " ThisModule " ) ,
390
+ scope: [ " A " ] ) )
391
+ {
392
+ #expect( nil != $0. outline ( reference: . lexical( ucf: Self . _string ( " f(_:) " ) ) ) )
393
+ #expect( nil != $0. outline ( reference: . lexical( ucf: Self . _string ( " g(_:) " ) ) ) )
394
+ #expect( nil != $0. outline ( reference: . lexical( ucf: Self . _string ( " h(_:) " ) ) ) )
395
+ #expect( nil != $0. outline ( reference: . lexical( ucf: Self . _string ( " i(_:) " ) ) ) )
396
+
397
+ #expect( nil == $0. outline ( reference: . lexical( ucf: Self . _string ( " w(_:) " ) ) ) )
398
+ #expect( nil == $0. outline ( reference: . lexical( ucf: Self . _string ( " x(_:) " ) ) ) )
399
+ #expect( nil == $0. outline ( reference: . lexical( ucf: Self . _string ( " y(_:) " ) ) ) )
400
+ #expect( nil == $0. outline ( reference: . lexical( ucf: Self . _string ( " z(_:) " ) ) ) )
401
+
402
+ #expect( $0. outlines ( ) == [
403
+ . vertex( 0 , text: " f(_:) " ) ,
404
+ . vertex( 2 , text: " g(_:) " ) ,
405
+ . vertex( 6 , text: " h(_:) " ) ,
406
+ . vertex( 10 , text: " i(_:) " ) ,
407
+ ] )
408
+ }
409
+ }
330
410
}
0 commit comments