Skip to content

Commit 4000084

Browse files
committed
Fix definition of DefinedType.getBaseType
1 parent 681f9af commit 4000084

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,13 @@ deprecated class NamedType = DefinedType;
10381038

10391039
/** A defined type. */
10401040
class DefinedType extends @definedtype, CompositeType {
1041-
/** Gets the type which this type is defined to be. */
1042-
Type getBaseType() { underlying_type(this, result) }
1041+
/**
1042+
* Gets the type which this type is defined to be, if available.
1043+
*
1044+
* Note that this is only defined for types declared in the project being
1045+
* analyzed. It will not be defined for type declared in external packages.
1046+
*/
1047+
Type getBaseType() { result = this.getEntity().(DeclaredType).getSpec().getTypeExpr().getType() }
10431048

10441049
override Method getMethod(string m) {
10451050
result = CompositeType.super.getMethod(m)
@@ -1049,7 +1054,7 @@ class DefinedType extends @definedtype, CompositeType {
10491054
or
10501055
// handle promoted methods
10511056
exists(StructType s, Type embedded |
1052-
s = this.getBaseType() and
1057+
s = this.getUnderlyingType() and
10531058
s.hasOwnField(_, _, embedded, true) and
10541059
// ensure `m` can be promoted
10551060
not s.hasOwnField(_, m, _, _) and
@@ -1063,7 +1068,7 @@ class DefinedType extends @definedtype, CompositeType {
10631068
)
10641069
}
10651070

1066-
override Type getUnderlyingType() { result = this.getBaseType().getUnderlyingType() }
1071+
override Type getUnderlyingType() { underlying_type(this, result) }
10671072
}
10681073

10691074
/**

0 commit comments

Comments
 (0)