mirror of
https://github.com/github/codeql.git
synced 2026-04-21 23:14:03 +02:00
Swift: add ConstructorDecl.isFailable/0
This commit is contained in:
@@ -602,12 +602,12 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
|
||||
c instanceof OptionalSomeContentSet
|
||||
)
|
||||
or
|
||||
// creation of an optional by returning from an optional initializer (`init?`)
|
||||
exists(ConstructorDecl init, OptionalType initRetType |
|
||||
// creation of an optional by returning from a failable initializer (`init?`)
|
||||
exists(ConstructorDecl init |
|
||||
node1.asExpr().(CallExpr).getStaticTarget() = init and
|
||||
node2 = node1 and // HACK: again, we should ideally have a separate Node case here, and not reuse the CallExpr
|
||||
c instanceof OptionalSomeContentSet and
|
||||
init.getInterfaceType().(FunctionType).getResult().(FunctionType).getResult() = initRetType
|
||||
init.isFailable()
|
||||
)
|
||||
or
|
||||
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1, c, node2)
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
private import codeql.swift.generated.decl.ConstructorDecl
|
||||
private import codeql.swift.elements.decl.MethodDecl
|
||||
private import codeql.swift.elements.type.FunctionType
|
||||
private import codeql.swift.elements.type.OptionalType
|
||||
|
||||
/**
|
||||
* An initializer of a class, struct, enum or protocol.
|
||||
*/
|
||||
class ConstructorDecl extends Generated::ConstructorDecl, MethodDecl {
|
||||
override string toString() { result = this.getSelfParam().getType() + "." + super.toString() }
|
||||
|
||||
/** Holds if this initializer returns an optional type. Failable initializers are written as `init?`. */
|
||||
predicate isFailable() {
|
||||
this.getInterfaceType().(FunctionType).getResult().(FunctionType).getResult() instanceof
|
||||
OptionalType
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user