Fix definition of DefinedType.getBaseType

This commit is contained in:
Owen Mansel-Chan
2025-06-03 14:31:44 +01:00
parent 681f9af710
commit 40000840c1

View File

@@ -1038,8 +1038,13 @@ deprecated class NamedType = DefinedType;
/** A defined type. */
class DefinedType extends @definedtype, CompositeType {
/** Gets the type which this type is defined to be. */
Type getBaseType() { underlying_type(this, result) }
/**
* Gets the type which this type is defined to be, if available.
*
* Note that this is only defined for types declared in the project being
* analyzed. It will not be defined for type declared in external packages.
*/
Type getBaseType() { result = this.getEntity().(DeclaredType).getSpec().getTypeExpr().getType() }
override Method getMethod(string m) {
result = CompositeType.super.getMethod(m)
@@ -1049,7 +1054,7 @@ class DefinedType extends @definedtype, CompositeType {
or
// handle promoted methods
exists(StructType s, Type embedded |
s = this.getBaseType() and
s = this.getUnderlyingType() and
s.hasOwnField(_, _, embedded, true) and
// ensure `m` can be promoted
not s.hasOwnField(_, m, _, _) and
@@ -1063,7 +1068,7 @@ class DefinedType extends @definedtype, CompositeType {
)
}
override Type getUnderlyingType() { result = this.getBaseType().getUnderlyingType() }
override Type getUnderlyingType() { underlying_type(this, result) }
}
/**