mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
Swift: Extract whether a function type is throwing or async.
This commit is contained in:
@@ -63,6 +63,7 @@ AnyFunctionType:
|
|||||||
param_types: Type*
|
param_types: Type*
|
||||||
param_labels: string*
|
param_labels: string*
|
||||||
is_throwing: predicate
|
is_throwing: predicate
|
||||||
|
is_async: predicate
|
||||||
|
|
||||||
AnyGenericType:
|
AnyGenericType:
|
||||||
_extends: Type
|
_extends: Type
|
||||||
|
|||||||
@@ -211,6 +211,14 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
|
|||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type->isThrowing()) {
|
||||||
|
dispatcher_.emit(AnyFunctionTypeIsThrowingTrap{label});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type->isAsync()) {
|
||||||
|
dispatcher_.emit(AnyFunctionTypeIsAsyncTrap{label});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label) {
|
void emitBoundGenericType(swift::BoundGenericType* type, TrapLabel<BoundGenericTypeTag> label) {
|
||||||
|
|||||||
@@ -27,4 +27,6 @@ class AnyFunctionTypeBase extends @any_function_type, Type {
|
|||||||
int getNumberOfParamLabels() { result = count(getAParamLabel()) }
|
int getNumberOfParamLabels() { result = count(getAParamLabel()) }
|
||||||
|
|
||||||
predicate isThrowing() { any_function_type_is_throwing(this) }
|
predicate isThrowing() { any_function_type_is_throwing(this) }
|
||||||
|
|
||||||
|
predicate isAsync() { any_function_type_is_async(this) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,6 +176,11 @@ any_function_type_is_throwing(
|
|||||||
int id: @any_function_type ref
|
int id: @any_function_type ref
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#keyset[id]
|
||||||
|
any_function_type_is_async(
|
||||||
|
int id: @any_function_type ref
|
||||||
|
);
|
||||||
|
|
||||||
@any_generic_type =
|
@any_generic_type =
|
||||||
@nominal_or_bound_generic_nominal_type
|
@nominal_or_bound_generic_nominal_type
|
||||||
| @unbound_generic_type
|
| @unbound_generic_type
|
||||||
|
|||||||
@@ -38,3 +38,4 @@
|
|||||||
| types.swift:21:10:21:10 | f | (Int) -> Int |
|
| types.swift:21:10:21:10 | f | (Int) -> Int |
|
||||||
| types.swift:21:10:21:13 | call to ... | Int |
|
| types.swift:21:10:21:13 | call to ... | Int |
|
||||||
| types.swift:21:12:21:12 | x | Int |
|
| types.swift:21:12:21:12 | x | Int |
|
||||||
|
| types.swift:25:10:25:10 | 42 | Int |
|
||||||
|
|||||||
@@ -20,3 +20,11 @@ func f(x: Int, y: Int) -> Int {
|
|||||||
func g(_ f: (Int) -> Int, _ x: Int) -> Int {
|
func g(_ f: (Int) -> Int, _ x: Int) -> Int {
|
||||||
return f(x)
|
return f(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func throwingFunc() throws -> Int {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
|
||||||
|
func asyncFunction(x: Int) async { }
|
||||||
|
|
||||||
|
func throwingAndAsyncFunction(x: Int) async throws { }
|
||||||
Reference in New Issue
Block a user