@@ -592,17 +592,17 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
592
592
or
593
593
// creation of an optional via implicit conversion,
594
594
// i.e. from `f(x)` where `x: T` into `f(.some(x))` where the context `f` expects a `T?`.
595
- exists ( InjectIntoOptionalExpr e , OptionalSomeDecl someDecl |
595
+ exists ( InjectIntoOptionalExpr e |
596
596
e .convertsFrom ( node1 .asExpr ( ) ) and
597
597
node2 = node1 and // HACK: we should ideally have a separate Node case for the (hidden) InjectIntoOptionalExpr
598
- c . isSingleton ( any ( Content :: EnumContent ec | ec . getParam ( ) = someDecl . getParam ( 0 ) ) )
598
+ c instanceof OptionalSomeContentSet
599
599
)
600
600
or
601
601
// creation of an optional by returning from an optional initializer (`init?`)
602
- exists ( ConstructorDecl init , OptionalType initRetType , OptionalSomeDecl someDecl |
602
+ exists ( ConstructorDecl init , OptionalType initRetType |
603
603
node1 .asExpr ( ) .( CallExpr ) .getStaticTarget ( ) = init and
604
604
node2 = node1 and // HACK: again, we should ideally have a separate Node case here, and not reuse the CallExpr
605
- c . isSingleton ( any ( Content :: EnumContent ec | ec . getParam ( ) = someDecl . getParam ( 0 ) ) ) and
605
+ c instanceof OptionalSomeContentSet and
606
606
init .getInterfaceType ( ) .( FunctionType ) .getResult ( ) .( FunctionType ) .getResult ( ) = initRetType
607
607
)
608
608
or
@@ -649,10 +649,10 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
649
649
)
650
650
or
651
651
// read of an optional .some member via `let x: T = y: T?` pattern matching
652
- exists ( OptionalSomePattern pat , OptionalSomeDecl someDecl |
652
+ exists ( OptionalSomePattern pat |
653
653
node1 .asPattern ( ) = pat and
654
654
node2 .asPattern ( ) = pat .getSubPattern ( ) and
655
- c . isSingleton ( any ( Content :: EnumContent ec | ec . getParam ( ) = someDecl . getParam ( 0 ) ) )
655
+ c instanceof OptionalSomeContentSet
656
656
)
657
657
}
658
658
@@ -672,15 +672,17 @@ predicate clearsContent(Node n, ContentSet c) {
672
672
predicate expectsContent ( Node n , ContentSet c ) { none ( ) }
673
673
674
674
/**
675
- * The global singleton `Optional.some` enum element .
675
+ * The global singleton `Optional.some` content set .
676
676
*/
677
- private class OptionalSomeDecl extends EnumElementDecl {
678
- OptionalSomeDecl ( ) {
679
- exists ( EnumDecl enum |
680
- this .getName ( ) = "some" and
681
- this .getDeclaringDecl ( ) = enum and
682
- enum .getName ( ) = "Optional" and
683
- enum .getModule ( ) .getName ( ) = "Swift"
677
+ private class OptionalSomeContentSet extends ContentSet {
678
+ OptionalSomeContentSet ( ) {
679
+ exists ( EnumDecl optional , EnumElementDecl some |
680
+ some .getDeclaringDecl ( ) = optional and
681
+ some .getName ( ) = "some" and
682
+ optional .getName ( ) = "Optional" and
683
+ optional .getModule ( ) .getName ( ) = "Swift"
684
+ |
685
+ this .isSingleton ( any ( Content:: EnumContent ec | ec .getParam ( ) = some .getParam ( 0 ) ) )
684
686
)
685
687
}
686
688
}
0 commit comments