Skip to content

Commit 6161ca3

Browse files
committed
add FeatureInheritanceAccessControl test case
1 parent 24a8dd6 commit 6161ca3

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -493,31 +493,10 @@ extension SSGC.TypeChecker
493493
let conformance:Symbol.Decl = feature.scopes.first
494494
else
495495
{
496-
// We hit this on an extremely unusual edge case where a feature and an heir
497-
// are public, but the protocol the feature is defined on is not. Here is some
498-
// valid Swift code that demonstrates this:
499-
//
500-
/* ```
501-
protocol P
502-
{
503-
}
504-
extension P
505-
{
506-
public
507-
func f()
508-
{
509-
}
510-
}
511-
512-
public
513-
struct S:P
514-
{
515-
}
516-
```
517-
*/
518-
// Ideally, lib/SymbolGraphGen would not emit the feature in this case, but
519-
// it does anyway.
520-
return
496+
throw AssertionError.init(message: """
497+
Declaration '\(feature.value.path)' has '\(feature.access)' access but \
498+
has no known lexical parents
499+
""")
521500
}
522501

523502
guard feature.scopes.count == 1
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import SymbolGraphCompiler
2+
@_spi(testable)
3+
import Symbols
4+
import Testing_
5+
6+
extension Main
7+
{
8+
enum FeatureInheritanceAccessControl
9+
{
10+
}
11+
}
12+
extension Main.FeatureInheritanceAccessControl:CompilerTestBattery
13+
{
14+
static
15+
let inputs:[Symbol.Module] =
16+
[
17+
"FeatureInheritanceAccessControl",
18+
]
19+
20+
static
21+
func run(tests:TestGroup, module:SSGC.ModuleIndex)
22+
{
23+
let declsBySymbol:[Symbol.Decl: SSGC.Decl] = module.declarations.reduce(into: [:])
24+
{
25+
for decl:SSGC.Decl in $1.decls
26+
{
27+
$0[decl.id] = decl
28+
}
29+
}
30+
let features:[Symbol.Decl: [Symbol.Decl]] = module.extensions.reduce(into: [:])
31+
{
32+
$0[$1.extendee.id, default: []] += $1.features
33+
}
34+
35+
36+
if let tests:TestGroup = tests / "S",
37+
let _:SSGC.Decl = tests.expect(
38+
value: declsBySymbol["s31FeatureInheritanceAccessControl1SV"])
39+
{
40+
tests.expect(nil: features["s31FeatureInheritanceAccessControl1SV"])
41+
}
42+
}
43+
}

Sources/SymbolGraphCompilerTests/Main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum Main:TestMain
99
Determinism.self,
1010
DefaultImplementations.self,
1111
FeatureInheritance.self,
12+
FeatureInheritanceAccessControl.self,
1213
ExternalExtensionsWithConformances.self,
1314
ExternalExtensionsWithConstraints.self,
1415
InternalExtensionsWithConformances.self,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
protocol P
2+
{
3+
func f()
4+
}
5+
extension P
6+
{
7+
public
8+
func f()
9+
{
10+
}
11+
}
12+
13+
/// This type exhibits a known lib/SymbolGraphGen bug, in that it “inherits” the nominally
14+
/// public ``P.f`` method, even though the protocol and all its members are internal.
15+
public
16+
struct S:P
17+
{
18+
}

0 commit comments

Comments
 (0)