mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
Address review comments
This commit is contained in:
@@ -164,13 +164,13 @@ private predicate hasEquivalentPositionalSibling(
|
||||
|
|
||||
forall(TypePath path0, Type t |
|
||||
t = getAssocFunctionNonTypeParameterTypeAt(impl, f, pos, path0) and
|
||||
path = path0.getAPrefixOrSelf()
|
||||
path = path0.getAPrefix()
|
||||
|
|
||||
t = getAssocFunctionNonTypeParameterTypeAt(sibling, f1, pos, path0)
|
||||
) and
|
||||
forall(TypePath path0, Type t |
|
||||
t = getAssocFunctionNonTypeParameterTypeAt(sibling, f1, pos, path0) and
|
||||
path = path0.getAPrefixOrSelf()
|
||||
path = path0.getAPrefix()
|
||||
|
|
||||
t = getAssocFunctionNonTypeParameterTypeAt(impl, f, pos, path0)
|
||||
)
|
||||
|
||||
@@ -1185,7 +1185,7 @@ private module ContextTyping {
|
||||
private Type inferCallTypeFromContextCand(AstNode n, TypePath prefix, TypePath path) {
|
||||
result = inferCallType(n, false, path) and
|
||||
hasUnknownType(n) and
|
||||
prefix = path.getAPrefixOrSelf()
|
||||
prefix = path.getAPrefix()
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
@@ -2704,10 +2704,9 @@ private module NonMethodResolution {
|
||||
// For inherent implementations of generic types, we also need to check the type being
|
||||
// implemented. We arbitrarily choose the first type parameter of the type being implemented
|
||||
// to represent this case.
|
||||
f = impl.getASuccessor(_) and
|
||||
f = impl.getAnAssocItem() and
|
||||
not impl.(Impl).hasTrait() and
|
||||
tp = TTypeParamTypeParameter(impl.resolveSelfTy().getTypeParam(0)) and
|
||||
not f.hasSelfParam() and
|
||||
pos.isSelf()
|
||||
}
|
||||
|
||||
@@ -2813,8 +2812,7 @@ private module NonMethodResolution {
|
||||
pragma[nomagic]
|
||||
NonMethodFunction resolveCallTargetNonBlanketCand(ImplItemNode i) {
|
||||
not this.hasTrait() and
|
||||
result = this.getPathResolutionResolved() and
|
||||
result = i.getASuccessor(_) and
|
||||
result = this.getPathResolutionResolved(i) and
|
||||
not exists(this.resolveCallTargetViaPathResolution()) and
|
||||
functionResolutionDependsOnArgument(i, result, _, _)
|
||||
}
|
||||
|
||||
@@ -206,6 +206,7 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
|
||||
exists(TypeParamItemNode tp | this = tp.getABoundPath() and result = tp)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private Type getDefaultPositionalTypeArgument(int i, TypePath path) {
|
||||
// If a type argument is not given in the path, then we use the default for
|
||||
// the type parameter if one exists for the type.
|
||||
@@ -228,6 +229,11 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
|
||||
this = any(PathTypeRepr ptp).getPath().getQualifier*()
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private TypeParameter getPositionalTypeParameter(int i) {
|
||||
result = this.resolveRootType().getPositionalTypeParameter(i)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default type for the type parameter `tp` at `path`, if any.
|
||||
*
|
||||
@@ -242,17 +248,14 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
|
||||
Type getDefaultTypeForTypeParameterInNonAnnotationAt(TypeParameter tp, TypePath path) {
|
||||
not this.isInTypeAnnotation() and
|
||||
exists(int i |
|
||||
result = this.getDefaultPositionalTypeArgument(pragma[only_bind_into](i), path) and
|
||||
tp = this.resolveRootType().getPositionalTypeParameter(pragma[only_bind_into](i))
|
||||
result = this.getDefaultPositionalTypeArgument(i, path) and
|
||||
tp = this.getPositionalTypeParameter(i)
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private Type getPositionalTypeArgument(int i, TypePath path) {
|
||||
result = getPathTypeArgument(this, i).getTypeAt(path)
|
||||
or
|
||||
// Defaults only apply to type mentions in type annotations
|
||||
this.isInTypeAnnotation() and
|
||||
result = this.getDefaultPositionalTypeArgument(i, path)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,9 +263,12 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
|
||||
* type parameter does not correspond directly to a type mention.
|
||||
*/
|
||||
private Type getTypeForTypeParameterAt(TypeParameter tp, TypePath path) {
|
||||
exists(int i |
|
||||
result = this.getPositionalTypeArgument(pragma[only_bind_into](i), path) and
|
||||
tp = this.resolveRootType().getPositionalTypeParameter(pragma[only_bind_into](i))
|
||||
exists(int i | tp = this.getPositionalTypeParameter(i) |
|
||||
result = this.getPositionalTypeArgument(i, path)
|
||||
or
|
||||
// Defaults only apply to type mentions in type annotations
|
||||
this.isInTypeAnnotation() and
|
||||
result = this.getDefaultPositionalTypeArgument(i, path)
|
||||
)
|
||||
or
|
||||
// Handle the special syntactic sugar for function traits. The syntactic
|
||||
|
||||
@@ -20,7 +20,7 @@ mod method_call_trait_path_disambig {
|
||||
#[derive(Default)]
|
||||
struct S;
|
||||
impl FirstTrait for S {
|
||||
// S::method2
|
||||
// S_as_FirstTrait::method2
|
||||
fn method2(&self) -> bool {
|
||||
true
|
||||
}
|
||||
@@ -31,7 +31,7 @@ mod method_call_trait_path_disambig {
|
||||
}
|
||||
}
|
||||
impl SecondTrait for S {
|
||||
// S::method2
|
||||
// S_as_SecondTrait::method2
|
||||
fn method2(&self) -> i64 {
|
||||
1
|
||||
}
|
||||
@@ -56,14 +56,14 @@ mod method_call_trait_path_disambig {
|
||||
let _b1 = FirstTrait::method(&s); // $ type=_b1:bool target=FirstTrait::method
|
||||
let _b2 = <S as FirstTrait>::method(&s); // $ type=_b2:bool target=FirstTrait::method
|
||||
let _b3 = <S as FirstTrait>::method(&Default::default()); // $ type=_b3:bool target=FirstTrait::method target=default
|
||||
let _b4 = <S as FirstTrait>::method2(&s); // $ type=_b4:bool target=S::method2
|
||||
let _b5 = <S as FirstTrait>::method2(&Default::default()); // $ type=_b5:bool target=S::method2 target=default
|
||||
let _b4 = <S as FirstTrait>::method2(&s); // $ type=_b4:bool target=S_as_FirstTrait::method2
|
||||
let _b5 = <S as FirstTrait>::method2(&Default::default()); // $ type=_b5:bool target=S_as_FirstTrait::method2 target=default
|
||||
|
||||
let _n1 = SecondTrait::method(&s); // $ type=_n1:i64 target=SecondTrait::method
|
||||
let _n2 = <S as SecondTrait>::method(&s); // $ type=_n2:i64 target=SecondTrait::method
|
||||
let _n3 = <S as SecondTrait>::method(&Default::default()); // $ type=_n3:i64 target=SecondTrait::method target=default
|
||||
let _n4 = <S as SecondTrait>::method2(&s); // $ type=_n4:i64 target=S::method2
|
||||
let _n5 = <S as SecondTrait>::method2(&Default::default()); // $ type=_n5:i64 target=S::method2 target=default
|
||||
let _n4 = <S as SecondTrait>::method2(&s); // $ type=_n4:i64 target=S_as_SecondTrait::method2
|
||||
let _n5 = <S as SecondTrait>::method2(&Default::default()); // $ type=_n5:i64 target=S_as_SecondTrait::method2 target=default
|
||||
|
||||
<S as FirstTrait>::function(); // $ target=S::function
|
||||
<S2 as FirstTrait>::function(); // $ target=S2::function
|
||||
|
||||
@@ -140,7 +140,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
|
||||
* Only holds when this list is non-empty, and only returns proper prefixes.
|
||||
*/
|
||||
bindingset[this]
|
||||
UnboundList getPrefix(int i) {
|
||||
UnboundList getProperPrefix(int i) {
|
||||
exists(string regexp, int occurrenceOffset | regexp = "[0-9]+\\." |
|
||||
exists(this.regexpFind(regexp, i, occurrenceOffset)) and
|
||||
result = this.prefix(occurrenceOffset)
|
||||
@@ -153,13 +153,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
|
||||
* Only holds when this list is non-empty, and only returns proper prefixes.
|
||||
*/
|
||||
bindingset[this]
|
||||
UnboundList getAPrefix() { result = this.getPrefix(_) }
|
||||
UnboundList getAProperPrefix() { result = this.getProperPrefix(_) }
|
||||
|
||||
/**
|
||||
* Gets a prefix of this list, including the list itself.
|
||||
*/
|
||||
bindingset[this]
|
||||
UnboundList getAPrefixOrSelf() { result = [this, this.getAPrefix()] }
|
||||
UnboundList getAPrefix() { result = [this, this.getAProperPrefix()] }
|
||||
}
|
||||
|
||||
/** Provides predicates for constructing `UnboundList`s. */
|
||||
|
||||
Reference in New Issue
Block a user