Skip to content

Commit 61f2d13

Browse files
asgerfCopilot
andcommitted
Unified: Hide TypeSelector from public API
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 64d9cd2 commit 61f2d13

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ClassLikeElement extends TClassLikeElement {
3535
ClassLikeDeclaration asClassLikeDeclaration() { this = TClassLikeDeclarationElement(result) }
3636

3737
/** Gets the type selector of this class, if it is only known from a model. */
38-
MaD::TypeSelector asTypeSelector() { this = TTypeSelectorElement(result) }
38+
private MaD::TypeSelector asTypeSelector() { this = TTypeSelectorElement(result) }
3939

4040
/**
4141
* Gets a declaration of this class, that is, either its primary declaration or an extension of it.

‎unified/ql/lib/codeql/unified/internal/mad/LegacyMaD.qll‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,7 @@ class TypeSelector extends string {
424424
}
425425

426426
/** Gets the class-like element corresponding to this type. */
427-
ClassLikeElement getClassLikeElement() {
428-
result.asTypeSelector() = this
429-
or
430-
result.asClassLikeDeclaration() = this.getDeclaration()
431-
}
427+
ClassLikeElement getClassLikeElement() { result.getQualifiedName() = this }
432428

433429
/** Gets the declaration of a proper subtype of this type (not the type itself). */
434430
ClassLikeDeclaration getASubtypeDeclaration() {
@@ -452,6 +448,12 @@ class TypeSelector extends string {
452448
CallExpr getAConstructorCall() { constructorCallSelector(result, this, _, _) }
453449
}
454450

451+
/** Gets the type selector of `element`, if it is only known from a model. */
452+
TypeSelector getTypeSelector(ClassLikeElement element) {
453+
result.getClassLikeElement() = element and
454+
not exists(element.asClassLikeDeclaration())
455+
}
456+
455457
private predicate isAccessPath(string path) {
456458
legacySourceModel(_, _, _, _, _, _, path, _, _) // output
457459
or

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import TypeMention
88
private import TypeInference
99
private import codeql.unified.internal.StaticNameBinding
1010
private import codeql.unified.internal.ParameterEx
11-
private import codeql.unified.internal.mad.LegacyMaD as MaD
1211

1312
/**
1413
* Holds if `a` is an associated type of `c`, in which case we model it
@@ -60,7 +59,7 @@ newtype TType =
6059
(
6160
exists(e.asClassLikeDeclaration().getNameNode())
6261
or
63-
exists(e.asTypeSelector())
62+
not exists(e.asClassLikeDeclaration())
6463
)
6564
} or
6665
TAliasType(TypeAliasDeclaration alias) or
@@ -140,9 +139,6 @@ class ClassLikeType extends TypeImpl, TClassLikeType {
140139
/** Gets the primary declaration of this type, if any. */
141140
ClassLikeDeclaration getClassLikeDeclaration() { result = e.asClassLikeDeclaration() }
142141

143-
/** Gets the type selector describing this type, if it is only known from a model. */
144-
MaD::TypeSelector getTypeSelector() { result = e.asTypeSelector() }
145-
146142
string getName() { result = e.getName() }
147143

148144
override Identifier getNameNode() { result = this.getClassLikeDeclaration().getNameNode() }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ private import codeql.typeinference.internal.TypeInference
2121
private import codeql.unified.internal.ParameterEx
2222
private import codeql.unified.internal.ExprPositions
2323
private import codeql.unified.internal.NameBinding
24+
private import codeql.unified.internal.mad.LegacyMaD as MaD
2425
private import utils.test.InlineExpectationsTest
2526
private import Type
2627
private import Type as T
@@ -895,7 +896,7 @@ module Input3 implements InputSig3 {
895896
result instanceof UnknownType
896897
or
897898
path.isEmpty() and
898-
n = result.(ClassLikeType).getTypeSelector().getAConstructorCall()
899+
n = MaD::getTypeSelector(result.(ClassLikeType).getClassLikeElement()).getAConstructorCall()
899900
}
900901

901902
predicate allowContextualInference(TypeMention tm, TypePath path) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ private import TypeInference
44
private import TypeInferencePlugin as Plugin
55
private import codeql.unified.internal.StaticNameBinding
66
private import codeql.unified.internal.ExprPositions
7+
private import codeql.unified.internal.mad.LegacyMaD as MaD
78

89
final class TypeMention = TypeMentionImpl;
910

@@ -281,7 +282,7 @@ class ExprTypeMention extends TypeMentionImpl, Expr {
281282
or
282283
result.(Plugin::TupleType).getArity() = this.(TupleExpr).getNumberOfElements()
283284
or
284-
result.(ClassLikeType).getTypeSelector().getAStaticRef() = this
285+
MaD::getTypeSelector(result.(ClassLikeType).getClassLikeElement()).getAStaticRef() = this
285286
}
286287

287288
override Type getUnexpandedType() {

0 commit comments

Comments
 (0)