Skip to content

Commit 12f09e4

Browse files
committed
wip
1 parent cd773cb commit 12f09e4

5 files changed

Lines changed: 809 additions & 784 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/NameBindingPlugin.qll‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ predicate isStaticMember(Member member) {
9999
exists(ClassLikeDeclaration cls | cls.getAMember() = member |
100100
not any(NameBindingPlugin p).isInstanceMember(cls, member) or
101101
member instanceof ConstructorDeclaration or
102-
member instanceof TypeAliasDeclaration
102+
member instanceof TypeAliasDeclaration or
103+
member instanceof ClassLikeDeclaration
103104
)
104105
or
105106
member = any(TopLevel t).getBody().getAStmt()

‎unified/ql/lib/codeql/unified/internal/typeinference/Type.qll‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ abstract private class TypeImpl extends TType {
101101
)
102102
}
103103

104+
/** Gets the parent type of this nested type, if any. */
105+
ClassLikeDeclarationType getParentType() {
106+
result.getClassLikeDeclaration() =
107+
this.getATypeParameter().(ParentTypeParameterType).getParent()
108+
}
109+
104110
/** Gets the name node of this type, if any. */
105111
abstract Identifier getNameNode();
106112

‎unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
/*
44
* Known limitations:
5-
* - Implicit constructors in classes and structs are not generated by the extractor
65
* - Pattern matching, including enum destructuring
76
* - Inferred qualifiers `.foo`
87
* - Type parameter bounds (`foo<T : Protocol>(x : T)`)
@@ -15,7 +14,6 @@
1514
* - Overloading (both arity based and type based)
1615
* - Indexing expressions
1716
* - Operations
18-
* - Inherited constructors
1917
* - Closure short-hand parameters `$0`, `$1`, etc (extractor change?)
2018
*/
2119

@@ -851,8 +849,9 @@ module Input3 implements InputSig3 {
851849
// `Optional.none` has an unknown `Wrapper` type
852850
exists(EnumField_ f, TypeParameter tp |
853851
n.(FieldAccess).getField() = f and
854-
tp = f.getType().getType().getATypeParameter() and
855-
path = TypePath::singleton(tp) and
852+
tp = f.getType().getType().getParentType*().getATypeParameter() and
853+
not tp instanceof ParentTypeParameterType and
854+
tp = f.getType().getTypeAt(path) and
856855
// `Optional<String>.none` does not have an unknown `Wrapper` type
857856
not exists(n.(MemberAccessExpr).getBase().(TypeMention).getTypeAt(path))
858857
) and

‎unified/ql/test/library-tests/type-inference/nested_types.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ class Outer<TOuter> {
114114
let c = p2.0.getOuter() // $ target=Outer.Inner.getOuter field=Tuple2.0 type=c:Bool
115115
let d = p2.0.getInner() // $ target=Outer.Inner.getInner field=Tuple2.0 type=d:Int
116116
}
117+
118+
enum E { case empty }
117119
}
118120

121+
let e: Outer<Int>.E = Outer.E.empty // $ field=Outer.E.empty type=.empty@Outer.E<(parent:E)>.Outer<TOuter>:Int
122+
119123
class Foo: Outer<String> {
120124
func f(x: Pair, y: Outer<Bool>.Pair) {
121125
var a = x.0.getInner() // $ target=Outer.Inner.getInner field=Tuple2.0 type=a:Int

0 commit comments

Comments
 (0)